musashine Posted June 7, 2006 Share Posted June 7, 2006 Hi im new at php and mysql and i was wondering if i can get the selected option of a menu and making it a variable before passing it to a database? Thanks, Any help would be much appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/11431-getting-the-value-of-menu-before-passing-to-a-database/ Share on other sites More sharing options...
SharkBait Posted June 7, 2006 Share Posted June 7, 2006 So you want to get an option someone selects, put it into a variable and then insert that into the database?[code]<form action="form.php" method="post"><select name="dropdown"> <option value="1">Option 1</option> <option value="2">Option 2</option> <option value="3">Option 3</option></select><input type="submit" value="submit" name="submit" /></form>[/code]Now the script side[code]<?php// Check to see if user clicked the submit buttonif(isset($_POST['submit'])) { // Get the option the user selected $option = $_POST['dropdown']; // Insert the option into the database // You will also need a database connection setup before this step.... $strqry = "INSERT INTO myTable (id, option) VALUES(null, '{$option}')"; $query = mysql_query($strqry) or die("MYSQL Error: <br />{$strqry} <br />". mysql_error()); } else { // Display the form to the user // Insert above HTML here to display the form }?>[/code]So $option will be 1, 2 or 3 depending on what the user selected in the drop down box when they click on the submit button.Though I am assuming you mean 'menu' as in a drop down menu on a HTML form of course. Quote Link to comment https://forums.phpfreaks.com/topic/11431-getting-the-value-of-menu-before-passing-to-a-database/#findComment-42896 Share on other sites More sharing options...
musashine Posted June 7, 2006 Author Share Posted June 7, 2006 Thank you very much! SharkBait, that code was just what i needed [img src=\"style_emoticons/[#EMO_DIR#]/laugh.gif\" style=\"vertical-align:middle\" emoid=\":laugh:\" border=\"0\" alt=\"laugh.gif\" /] Quote Link to comment https://forums.phpfreaks.com/topic/11431-getting-the-value-of-menu-before-passing-to-a-database/#findComment-42923 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.