Jump to content


This topic is now archived and is closed to further replies.


Drop down menu

Recommended Posts

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?

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 present
if (!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";

Share this post

Link to post
Share on other sites
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.

Share this post

Link to post
Share on other sites
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.

Share this post

Link to post
Share on other sites
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?

Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.