jeaker Posted April 28, 2007 Share Posted April 28, 2007 I have a website that I am working on. When the user logs in they see a drop down box and they are supposed to go to this box and select their name. How would I get the selection that they made to pass to the next page. This is my code for the page with the drop down box that I have so far. It pulls from my database, and it works fine. <?php // Connect to the upload datbase on localhost. mysql_connect('localhost','user','password'); mysql_select_db('upload'); // Query the teacher table and load all of the records // into an array. $sql = 'SELECT * FROM teacher'; $res = mysql_query($sql) or die(mysql_error()); while ($rec = mysql_fetch_assoc($res)) $teacher[] = $rec; ?> <title>Untitled Document</title> </head> <body> <?php echo '<SELECT name="dropdown">'; foreach ($teacher as $t) echo "<OPTION>{$t['fname']}, {$t['lname']}</OPTION>\n"; echo '</SELECT>'; ?> </body> </html> Any help or advice would be greatly appreciated. Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/49036-solved-passing-data-from-a-drop-down-menu/ Share on other sites More sharing options...
MadTechie Posted April 28, 2007 Share Posted April 28, 2007 bascially your creating a form, so your need a button or some javascript, then use $_GET or $_POST ie <form method="POST" action="page2.php"> <?php echo '<SELECT name="dropdown">'; foreach ($teacher as $t) echo "<OPTION>{$t['fname']}, {$t['lname']}</OPTION>\n"; echo '</SELECT>'; ?> </form> page2.php <?php echo $_POST['dropdown']; ?> Quote Link to comment https://forums.phpfreaks.com/topic/49036-solved-passing-data-from-a-drop-down-menu/#findComment-240234 Share on other sites More sharing options...
snowdog Posted April 28, 2007 Share Posted April 28, 2007 You need to put it into a form with a submit button. Like this. <form method=POST name="userdata" action="your_next_page.php"> <?php echo '<SELECT name="dropdown">'; foreach ($teacher as $t) echo "<OPTION>{$t['fname']}, {$t['lname']}</OPTION>\n"; echo '</SELECT>'; ?> <input type="submit" value="Submit Info" onmouseover="this.className='buttonon'" onmouseout="this.className='button'" class="button"><br><br><br> </form> Quote Link to comment https://forums.phpfreaks.com/topic/49036-solved-passing-data-from-a-drop-down-menu/#findComment-240235 Share on other sites More sharing options...
MadTechie Posted April 28, 2007 Share Posted April 28, 2007 lol yeah and the button LMAO revised <form method="POST" action="page2.php"> <?php echo '<SELECT name="dropdown">'; foreach ($teacher as $t) echo "<OPTION>{$t['fname']}, {$t['lname']}</OPTION>\n"; echo '</SELECT>'; ?> <input type="submit" name="submit" value="Page2"> </form> thanx for point that out snowdog Quote Link to comment https://forums.phpfreaks.com/topic/49036-solved-passing-data-from-a-drop-down-menu/#findComment-240241 Share on other sites More sharing options...
jeaker Posted April 28, 2007 Author Share Posted April 28, 2007 WOW, so simple. You guys saved me. Thanks so much. Quote Link to comment https://forums.phpfreaks.com/topic/49036-solved-passing-data-from-a-drop-down-menu/#findComment-240242 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.