PDA

View Full Version : Dropdown tutorial help


ali_b
04-27-2007, 12:50 PM
Hello,

I have completed the beginners tutorial and i moved onto the dropdown neu tutorial.

i tested it but im getting this error.

"Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\Documents and Settings\Ali\My Documents\web root\test\dropdown.php on line 10"

Line 10 is : $rowModel = mysql_fetch_array($result);

I put @ at the beginging of mysql... dont no if i should have done that but i tried it again but the second dropdown doesnt populate.

here is my code:

<?php
require_once("connections/connection.php"); // database connection
$make = $_POST['make'];
if ($make){
/////////////////////////////////////////////
$query = sprintf("SELECT * FROM car_model where care_model_id='$make'");
$result = @mysql_query($query);
$rowModel = mysql_fetch_array($result);
/////////////////////////////////////////////
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<form form id="form1" name="form1" action="dropdown.php" method="post">
<select name="make" onChange="document.forms[0].submit()">
<option value"" selected>Select Make</option>
<option value="1">Alfa Romeo</option>
<option value="2">Audi</option>
<option value="3">BMW</option>
<option value="4">Citroen</option>
</select>

<select name="model">
<option value="">Select Model</option>
<?php do { ?>
<option value="<?php echo $rowModel['car_model_id']; ?>"><?php echo $rowModel['car_model']; ?></option>
<?php }while ($rowModel = mysql_fetch_array($result)); ?>
</select>
</form>
</body>
</html>


cheers for ur help in advance :)

davidj
04-27-2007, 01:23 PM
post the code

all of the code as you have written it

ali_b
04-27-2007, 01:27 PM
<?php
require_once("connections/connection.php"); // database connection
$make = $_POST['make'];
if ($make){
/////////////////////////////////////////////
$query = sprintf("SELECT * FROM car_model where care_model_id='$make'");
$result = @mysql_query($query);
$rowModel = mysql_fetch_array($result);
/////////////////////////////////////////////
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<form form id="form1" name="form1" action="dropdown.php" method="post">
<select name="make" onChange="document.forms[0].submit()">
<option value"" selected>Select Make</option>
<option value="1">Alfa Romeo</option>
<option value="2">Audi</option>
<option value="3">BMW</option>
<option value="4">Citroen</option>
</select>

<select name="model">
<option value="">Select Model</option>
<?php do { ?>
<option value="<?php echo $rowModel['car_model_id']; ?>"><?php echo $rowModel['car_model']; ?></option>
<?php }while ($rowModel = mysql_fetch_array($result)); ?>
</select>
</form>
</body>
</html>

ali_b
04-27-2007, 01:30 PM
oops i think i may have found the problem


yup my variable was spelt wrong.... oops lol