...

View Full Version : Working with DropDown Menus in PHP



srule_
11-21-2007, 11:44 PM
Hello,

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" >
<p>
<select id="jump-button">
<option selected="selected">Choose A Color</option>
<?php

// 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);
?>
</select>

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

</form>



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.

srule_
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.

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

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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum