By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,746 Members | 1,928 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,746 IT Pros & Developers. It's quick & easy.

cascading dropdown menus

P: 1
Hello everyone:
I need to make a dropdown menu that shows information depending on what the user chooses in the first one. I am using PHP and MySql.
I am new!

I looked for tutorials and I am trying to understand the code... however it is not clear enough. I will say what I understand so you can tell me where I am wrong.
Expand|Select|Wrap|Line Numbers
  1. <?PHP      
  2. require_once('connection.php');
  3. require_once('open_db.php');
  4.  
  5. $query1=mysql_query("SELECT Route_From as Desde FROM route") or die(mysql_error());
  6. $query2=mysql_query("SELECT * FROM route WHERE Route_From=".$_POST["Desde"]."&quot;") or die(mysql_error());
  7. ?>
  8.  
  9. <form name="check" method="post">
  10.    <!-- First Drop Down starts here -->
  11.       <select name="select1" onchange="this.form.submit()">
  12.          <?PHP
  13.             while ($row = mysql_fetch_assoc($query1)) 
  14.             {
  15.                 echo ("<option>{$row['Route_From']}</option>");
  16.             }
  17.           ?>
  18.       </select>
  19.  
  20.    <?PHP
  21.       if (isset($_POST["select1"]))
  22.    ?>
  23.    <select name="select2">
  24.    <?PHP
  25.       while($row = mysql_fetch_assoc($query2))
  26.       {
  27.          echo("<option>{$row['Route_To']}</option>");
  28.       }
  29.    ?>
  30.    </select>
  31. </form>
  32.  
Ok, so what I understand is:
- I connect to MySql (that works fine)
- I create the queries
- I create the first menu and start filling it up and with the "onchange", when a user selects an option, what he chose is submitted.
- When the first option is submitted, this info is captured with:
<?PHP
if (isset($_POST["select1"]))
?>
- The the second query is done and the second menu is filled.

When I execute the page the error that is shown is the following:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '"' at line 1

I hope someone can help me!
Bye
May 2 '07 #1
Share this Question
Share on Google+
6 Replies


ak1dnar
Expert 100+
P: 1,584
Replace this line and let me know the status.

[PHP]$query2=mysql_query('SELECT * FROM route WHERE Route_From='.$_POST['Desde'].'') or die(mysql_error());[/PHP]
May 3 '07 #2

P: 8
Just replace your $query2 line with this :

$query2=mysql_query("SELECT * FROM route WHERE Route_From='".$_POST["Desde"]."'") or die(mysql_error());
May 4 '07 #3

P: 65
Hello,
I had faced same problem..if user select the item in <select> then the below got one textarea to display the description of item..what should i write the code..

from <select> i retrieve all the item from db and then i want based on the user select the item then show the description of the item that what user was selected..

Can some one guide me...
May 15 '07 #4

ak1dnar
Expert 100+
P: 1,584
wish,
After getting the result set row values print it in side the teaxarea.

[PHP]<textarea name="description" cols="5" rows="5"><? echo $the_description ?></textarea>[/PHP]
May 15 '07 #5

P: 65
Thank you my friend...
One problem is settle but another problem prompt out..
because based on the above example, the <form name="change" method="post"> the action property is no use then when i click button to submit..it can not work..if i add action property in the form tag then when i select the item then it direct go to another page...then what should i write the code...

Can you guide me again..
May 15 '07 #6

ak1dnar
Expert 100+
P: 1,584
Thank you my friend...
One problem is settle but another problem prompt out..
because based on the above example, the <form name="change" method="post"> the action property is no use then when i click button to submit..it can not work..if i add action property in the form tag then when i select the item then it direct go to another page...then what should i write the code...

Can you guide me again..
Its better to post a new thread for this question,Its not a good idea to continue with this tread here after.because this is not related to the thread of yo123.
May 15 '07 #7

Post your reply

Sign in to post your reply or Sign up for a free account.