Jump to content


Drop down menu

  • Please log in to reply
3 replies to this topic

#1 Fearpig

  • Members
  • PipPipPip
  • Advanced Member
  • 195 posts

Posted 07 September 2006 - 01:46 PM

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";

"Whats wrong with the cat?" - Mrs Schrödinger

#2 ober

  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 07 September 2006 - 02:28 PM

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.

Info: PHP Manual

#3 Fearpig

  • Members
  • PipPipPip
  • Advanced Member
  • 195 posts

Posted 07 September 2006 - 02:33 PM

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.
"Whats wrong with the cat?" - Mrs Schrödinger

#4 Barand

  • Moderators
  • Sen . ( ile || sei )
  • 18,016 posts

Posted 07 September 2006 - 02:34 PM

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?
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received


|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users