I am creating an update form where previously submitted information from a mysql database is grabbed to populate the current form. So this is what I have so far:
$select = mysql_query("SELECT * FROM some_table WHERE id = $id");
while ($return = mysql_fetch_assoc($select)) {
$name = $return['name'];
$bio = $return['bio'];
$maritalStatus = $return['marital_status'];
$favFood = $return['fav_food'];
}
<form action="page.php" method="post">
Name: <input type="text" name="name" value="<?php echo $name; ?>" /><br />
Bio: <textarea name="bio"><?php echo $bio; ?></textarea><br />
Marital Status
<select name="maritalStatus">
<option>Select One</option>
<option value="married">Married</option>
<option value="single">Single</option>
<option value="divorced">Divorced</option>
</select><br />
Favorite Food:
Cheeze: <input type="checkbox" name="favFood" value="cheeze" />
Cake: <input type="checkbox" name="favFood" value="cake" />
Oranges: <input type="checkbox" name="favFood" value="oranges" />
</form>
As you can see I am able to display data that was entered via an input text box or textarea just fine. But How to I have the "Marital Status" drop down preselected to the "divorced" option and the "Oranges" check box checked under "Favorite Food" GIVEN that those two choices are the ones that actually exist in the database?