logo-dw

Go Back   Dreamweaver Club Forums > Dreamweaver forums > Video Tutorials
Register FAQ Members List Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Display Modes
Old 08-30-2007, 09:31 PM   #1
iainb
 
Join Date: Aug 2007
Posts: 14
Default Problem with Dropdown tutorial

Hi again.

I'm having a problem with this one. I have read other threads on this topic and cant get an answer. As far as I can see the code is the same as yours apart from another @ to stop a warning being echo'd...

The second dropdown is not being populated when the page is submitted, I will post the code so you can see. Any help is greatly appreciated.

Quote:
<?php
require_once("Connections/connection.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=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="<?php $_SERVER['PHP_SELF']; ?>">
<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>
Thanks for any help you can give.

iain
iainb is offline   Reply With Quote
Old 08-30-2007, 10:46 PM   #2
davidj
davidj's Avatar
 
Join Date: Sep 2005
Location: The Toon (newcastle upon Tyne)
Posts: 8,256
Default

does the form submit when you change the value
__________________
Would you like to learn PHP from me? Check out -> www.codezenith.co.uk
davidj is offline   Reply With Quote
Old 08-30-2007, 10:57 PM   #3
iainb
 
Join Date: Aug 2007
Posts: 14
Default

hi,

yeah the form submits fine, but then both fields stay as they were.... car make dropdown populated, and nothing in the model dropdown

iain
iainb is offline   Reply With Quote
Old 08-31-2007, 09:20 AM   #4
davidj
davidj's Avatar
 
Join Date: Sep 2005
Location: The Toon (newcastle upon Tyne)
Posts: 8,256
Default

instead of this...
Code:
onChange="document.forms[0].submit()"
try this...
Code:
 
onChange="document.submit()"
__________________
Would you like to learn PHP from me? Check out -> www.codezenith.co.uk
davidj is offline   Reply With Quote
Old 08-31-2007, 11:05 AM   #5
iainb
 
Join Date: Aug 2007
Posts: 14
Default

hi,

ok, I tried the ammended code you gave me... That didnt work either.

This time when I chose something from the "make" dropdown, it no longer submits the page as it did with the original code, so obviously doesnt populate the second dropdown.

iain
iainb is offline   Reply With Quote
Old 08-31-2007, 01:25 PM   #6
davidj
davidj's Avatar
 
Join Date: Sep 2005
Location: The Toon (newcastle upon Tyne)
Posts: 8,256
Default

ok lets debug this

where you have

PHP Code:
$query sprintf("SELECT * FROM car_model where car_model_id='$make'"); 
add an echo to the begining

PHP Code:
echo $query sprintf("SELECT * FROM car_model where car_model_id='$make'"); 
now run the script by selecting a dropdown value again

the browser will echo the SQL and may display a warning which is fine as its just reporting its done something wrong which we know about

paste the SQL in this thread
__________________
Would you like to learn PHP from me? Check out -> www.codezenith.co.uk
davidj is offline   Reply With Quote
Old 08-31-2007, 03:38 PM   #7
iainb
 
Join Date: Aug 2007
Posts: 14
Default

hi

ok, done that and yes there is an error.....

Parse error: syntax error, unexpected T_ECHO in C:\wamp\www\Web Root\Test\dropdown.php on line 8

iain
iainb is offline   Reply With Quote
Old 08-31-2007, 04:29 PM   #8
iainb
 
Join Date: Aug 2007
Posts: 14
Default

line 8 is the......

echo $query = sprintf("SELECT * FROM car_model where car_model_id='$make'");

by the way
iainb is offline   Reply With Quote
Old 08-31-2007, 05:28 PM   #9
davidj
davidj's Avatar
 
Join Date: Sep 2005
Location: The Toon (newcastle upon Tyne)
Posts: 8,256
Default

ok
thats weird

try this... Add the echo below and remove the one you had

where you have.....
PHP Code:
$query sprintf("SELECT * FROM car_model where car_model_id='$make'");
$result = @mysql_query($query); 
$rowModel = @mysql_fetch_array($result);
 
echo 
$query
__________________
Would you like to learn PHP from me? Check out -> www.codezenith.co.uk
davidj is offline   Reply With Quote
Old 08-31-2007, 07:40 PM   #10
iainb
 
Join Date: Aug 2007
Posts: 14
Default

ok, tried that....

the page submits but the second dropdown is still not being populated... it returns the $query as...

SELECT * FROM car_model where car_model_id='1'

I just checked the database, and the fields are definately using those names (as in video)... and it only uses ID's 1 - 4

cheers

iain

Last edited by iainb; 08-31-2007 at 07:43 PM..
iainb is offline   Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 11:17 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Copyright 2006 DreamweaverClub.com