I was following a tutorial on PHP and HTML on how to use option=selected, but I am confused.
Here is my code:
<form name ="rating" method ="POST" action ="" />
<? echo "<input type = \"hidden\" name = accountID value = " . $row['accountID'] . ">";?>
<select name="rating">
<? $values = array('','Very Bad','Bad','Average','Above Average');
for ($i =0; $i < count($values); $i = $i + 1){
echo "<option value = \"$i\"" . if ($rating == $i + 1) {echo "selected";} . "> $values[$i] </option>";
}
?>
</select>
<input type ="Submit" name ="formSubmit" value ="Submit">
</form>
<?
What I am trying to achieve is to have whatever option is stored in the database to be selected by default. What am I missing in the code?
try this out it will be what u want
EDIT:
yes this variable
$ratingis not defined . so try to define it like thatput it before this
formsomewhere inside php tag