I have the following code that populates a drop down menu with data from a mysql database.
I would like to include it in a form and pass the selected value to a results page but am unsure how. Here is my code:-
<?php
$host = 'localhost';
$user = 'x';
$pass = 'x';
$db = 'x';
$table = 'houses';
$link = mysql_connect($host,$user,$pass);
if(!$link) die(mysql_error());
$select = mysql_select_db($db);
if(!$select) die(mysql_error());
$query = "SELECT DISTINCT areas FROM houses ORDER BY areas";
$result = mysql_query($query);
if(!$result) die(mysql_error());
echo "<select name=\"areas\">\n";
echo "<option value=\"\">Choose</option>\n";
while($row = mysql_fetch_array($result))
{
// added this
if ($choose == $row['areas'])
$selected = ' selected';
else
$selected = '';
echo "<option value='".$row['areas']."'$selected>".$row['areas']."</option>\n";
}
echo "</select>\n";
?>
Thanks.