Following is my Php code where all country come from mysql database. It's a user profile area where users can update their country name. But it's not selected (html selected = selected) after he submit his country name. May be it's my $sel variable problem. Can some one fix it ?
<select name="country" class="country">
<?php
$sql=mysql_query("select * from country");
while($row=mysql_fetch_array($sql))
{
$id=$row['Code'];
$data=$row['Name'];
if($data == $country2)
{
$sel = 'selected = "selected"';
}
else
{
$sel = "";
}
echo '<option value="'.$id.'" $sel>'.$data.'</option>';
}
?>
</select>