View Full Version : Working with DropDown Menus in PHP

11-21-2007, 11:44 PM

I made a drop down menu that is dynamically populated with info from my MySQL database. The code is:

<form name="formone" method="post" action="search.php" >
<select id="jump-button">
<option selected="selected">Choose A Color</option>

// do...while loop to dispay table data
do {

echo '<option name="colors" value="'.$row['color_one'].'">'.$row['color_one'].'</option>';

$row = mysql_fetch_assoc($result);

} while ($row);

<input name="send" id="send" type="submit" value="Send message" />


What I am having trouble figuring out is how to set the input field the user chooses to "selected", then storing the "selected" value in a variable to be used in a later query.

Any tips?

Velox Letum
11-22-2007, 01:00 AM
Do you mean that you wish to store which option they select and submit the form? Well, $_POST['colors'] will have the color they selected.

11-22-2007, 03:23 AM
yes that what I mean but that does not work.

I did the following code to test it:

if (isset($_POST['send'])) {

$colorSearch = $_POST['colors'];
echo $colorSearch;

nothing is outputed.

11-22-2007, 03:26 AM
Move name="colors" into the select tag.

11-22-2007, 04:24 AM
Thanks Inigoesdr,