Hi!
I tried to get a listbox to set the default value depending on the data stored in a mySQL database but I connot figure out how.
Here's the code that I have :
<?php
$db = mysql_connect('localhost', 'username', 'password');
mysql_select_db('database',$db);
$sql = "SELECT field1, field2, field3 FROM table1 WHERE id='$id'";
$req = mysql_query($sql) or die('Erreur SQL <br>'.$sql.'<br>'.mysql_error());
while($data= mysql_fetch_assoc($req))
{
Basicly if field1 = option2 in mySQL. Then the default selected value should be Option 2
echo "
<select name=select selected="$data[field1]">
<option value=option1>Option 1</option>
<option value=option2>Option 2</option>
<option value=option3>Option 3</option>
<option value=option4>Option 4</option>
<option value=option5>Option 5</option>
</select>
";
}
?>
If anyone can help me out it would be really appreciated! Thanks!!