alanlaw87 Posted August 15, 2010 Share Posted August 15, 2010 Hi I have coded a drop down menu with php and i am trying to retrieve the data when a user select a option from the menu and the data is retrieved from the database. So far i have tried and nothing is displaying when i tried to process the php form. Sales.php Page <form action="saleprocess.php" method="GET"> <?php echo 'Product Model:'; $query="SELECT * FROM products"; /* You can add order by clause to the sql statement if the names are to be displayed in alphabetical order */ $result = mysql_query ($query); echo "<select name=product_model value=Select>Product Model</option>"; // printing the list box select command while($rows=mysql_fetch_array($result)){//Array or records stored in $nt echo "<option name=product_model value='.$rows[product_id].'>$rows[product_model]</option>"; /* Option values are added by looping through the array */ } echo "</select><br>"; ?> <input type='submit' name='submit' value='Create'></input> <br> </form> ******************************************************************************** Salesprocess.php page <?php include("connect.php"); if(isset($_GET['product_id'])){ $product_id = $_GET['product_id']; $query = mysql_query("SELECT * FROM products WHERE product_id= $product_id"); while($rows = mysql_fetch_assoc($query)) { echo 'Product Model<br>'; echo $rows['product_id']; echo $rows['product_model']; } } ?> Muchly appreciated if someone can help me Quote Link to comment https://forums.phpfreaks.com/topic/210774-drop-down-menu-retrieve-data-help/ Share on other sites More sharing options...
wildteen88 Posted August 15, 2010 Share Posted August 15, 2010 You are coding the drop down menu incorrectly. Correct syntax for a drop down is <select name="menu_name"> <option value="value1">value1</option> <option value="value2">value2</option> <option value="value3">value3</option> ... etc ... <select> Notice you only give the opening <select> tag a name. Each <option></option> has a unique value given to it. You can retrieve the selected value, by using either $_GET['menu_name'] or $_POST['menu_name'] (depending your forms submit method). Corrected code echo "Product Model: <select name=\"product_model\">"; // printing the list box select command while($rows = mysql_fetch_array($result)) {//Array or records stored in $nt echo "<option value=\"{$rows['product_id']}\">{$rows['product_model']}</option>"; /* Option values are added by looping through the array */ } echo "</select><br />"; Please use or tags when posting code. It'll make reading your code alot easier Quote Link to comment https://forums.phpfreaks.com/topic/210774-drop-down-menu-retrieve-data-help/#findComment-1099495 Share on other sites More sharing options...
alanlaw87 Posted August 15, 2010 Author Share Posted August 15, 2010 Thank You so much my form is working Quote Link to comment https://forums.phpfreaks.com/topic/210774-drop-down-menu-retrieve-data-help/#findComment-1099498 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.