PDA

View Full Version : error


mr_badger
06-30-2007, 09:46 PM
I have done the dropdown menu tutorial and I'am getting this message
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in

heres my code.
<?php
require_once('Connections/conn.php');

$make = $_POST['make'];


if ($make){
/////////////////////////////////////////////////
$query = sprintf("SELECT * FROM car_model where car_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 id="form1" name="form1" method="post" action="dropdown.php" >

<select name="make" onChange="document.forms[0].submit()">
<option value="">Select Make</option>
<option value="1" <?php if(!(strcmp(1, $make))){echo "selected";}?>>Alfa Romeo</option>
<option value="2" <?php if(!(strcmp(2, $make))){echo "selected";}?>>Audi</option>
<option value="3" <?php if(!(strcmp(3, $make))){echo "selected";}?>>BMW</option>
<option value="4" <?php if(!(strcmp(4, $make))){echo "selected";}?>>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>

davidj
06-30-2007, 10:37 PM
thats correct

its a warning which is displaying correctly. Just stick an @ infront of the function to supress it


@mysql_fetch_array():

mr_badger
07-01-2007, 04:59 PM
ok I have done that and there is no error message but I'am not getting any data in the second dropdown when I choose from the first drop down?

davidj
07-01-2007, 05:42 PM
where you have

/////////////////////////////////////////////////
$query = sprintf("SELECT * FROM car_model where car_model_id='$make'");
$result = @mysql_query($query);
$rowModel = mysql_fetch_array($result);
/////////////////////////////////////////////////

add an echo like this...


/////////////////////////////////////////////////
echo $query = sprintf("SELECT * FROM car_model where car_model_id='$make'");
$result = @mysql_query($query);
$rowModel = mysql_fetch_array($result);
/////////////////////////////////////////////////


try selecting the dropdown then post the resulting message to the screen

mr_badger
07-02-2007, 12:12 AM
now when I select a make I get this message, SELECT * FROM car_model where car_model_id='3

Nothing in the second dropdown.

davidj
07-02-2007, 06:33 AM
ok thats fine. You are passing in an ID correctly. Does that ID exist in the db?

mr_badger
07-02-2007, 11:08 AM
Yes that id does exsist in the database, but could it be to do with NULL and NOT NULL in the database because I have 'make' in the car make table as NULL and both 'car_Model_id' and 'car_model' in the car model table as NULL.

davidj
07-02-2007, 03:10 PM
do you have a value in the tables

2 tables both with data and both have a relationship id

mr_badger
07-02-2007, 09:42 PM
yes I have all that.

davidj
07-03-2007, 06:42 AM
i cant see any problem with the code

if you echo...


echo $rowModel['car_model_id'];


do you see any results

davidj
07-03-2007, 06:44 AM
also

where you have...


}while ($rowModel = mysql_fetch_array($result));


change $rowModel to $row