I have a dropdown menu in a form that is dynamic and pulls in the options from a database. It works great. The only problem is if there is an error in the form when it is submitted all of the values that were entered are cleared. How can I make my drop down menu sticky so that it keeps the values that were entered when an error occurs upon submission of the form?
Here is the code for my drop down:
<div class="field">
<label for="machinenum">Machine #</label>
<select name="machinenum">
<option value="null">Choose One</option>
$conn = mysql_connect("localhost","user","pass") or trigger_error("SQL", E_USER_ERROR);
$db = mysql_select_db("database", $conn) or trigger_error("SQL", E_USER_ERROR);
$sql_machinenum = "SELECT * FROM machinenum ORDER BY machinenum_drop ASC";
$result = mysql_query($sql_machinenum, $conn) or trigger_error("SQL", E_USER_ERROR);
while($row = mysql_fetch_assoc($result)) {
$selection = $row['machinenum_drop'];
$machinenum_tbl = $row['machinenum'];
if ($row['machinenum_drop'] == $machinenum_tbl){
echo "<option value=\\"$selection\\" SELECTED>$selection</option>\
";
}else{
echo "<option value=\\"$selection\\">$selection</option>\
";
}
}
mysql_close($db);
</select>
</div>