Jump to content

Drop down menu


Fearpig

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?


[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 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";
?>
[/code]
Link to comment
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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.