Fearpig Posted September 7, 2006 Share Posted September 7, 2006 Hello again guys! :)I've got another problem thats bugging me. I've set up a page that has a product name and then a list of part numbers associated with that product. I then wanted to put a drop down menu so the user can select which product is displayed. I've managed to populate the drop down menu but when I click submit it doesn't pass on the variable. Its all on one page and $id should default to the value of 2 if it hasn't been set. Can anyone see where I've gone wrong?[code]include '../ConnectMySQL.php';$query = mysql_query("SELECT Model FROM tbl_parts");echo "<form action=test.php method=POST><select name=id>";while ($r = mysql_fetch_array($query)){$id2 = $r["ID"];$Model = $r["Model"];echo "<option value=$id2>$Model</option>";}echo "</select><input type='submit' name='Submit' value='Submit'></form>";//Use ID=2 if no id presentif (!isset($_GET['id'])){ $id = "2";}$sql = "SELECT * FROM tbl_parts WHERE ID=$id";$result = mysql_query($sql); $myrow = mysql_fetch_array($result);echo "<span class='Body2'><b>Boiler Model: ";echo $myrow["Model"];echo "</b></span>";echo "<br><br><table width='350' class='Body2' border=1 cellspacing='0'>\n";echo "<tr bgcolor=#CCCCCC><td width='200' align='center'><b>Description</b></td><td width='150' align='center'><b>Part No.</b></td></tr>\n";echo "<tr><td>Electrode - Flame Sensing</td><td>";echo $myrow["Electrode - Flame Sensing"];echo "</td></tr>\n";//loads of parts missed out for clarity!echo "<tr><td>Washer 3/4 Inch</td><td>";echo $myrow["Washer 3/4 Inch"];echo "</td></tr></table>\n";?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/20010-drop-down-menu/ Share on other sites More sharing options...
ober Posted September 7, 2006 Share Posted September 7, 2006 Where is the code from the page you're submitting this to? Also, you don't handle the situation where the id IS set. You need to have a default value of $id or set it when $_GET['id'] is actually set.Also, a few other picky points. Your code is invalid. All attributes of an html tag should be enclosed in double quotes.Another thing I just noticed is that you're checking the $_GET array in your if statement, but you're submitting the form with the POST method. You may want to use the $_REQUEST (contains get and post) array or the $_POST array to check for your values. Quote Link to comment https://forums.phpfreaks.com/topic/20010-drop-down-menu/#findComment-87761 Share on other sites More sharing options...
Fearpig Posted September 7, 2006 Author Share Posted September 7, 2006 Sorry... just ignore this one!!!!I've just re-read my code and spotted loads of errors myself (its been a long day!!) I'll sit down and try again!Thanks Ober. Quote Link to comment https://forums.phpfreaks.com/topic/20010-drop-down-menu/#findComment-87768 Share on other sites More sharing options...
Barand Posted September 7, 2006 Share Posted September 7, 2006 What is your table structure?Is there just a single table for model and parts?If so, is there a part id and a model id in the same record? Quote Link to comment https://forums.phpfreaks.com/topic/20010-drop-down-menu/#findComment-87770 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.