<?php

$query=mysqli_query($con,"select * from reg where user_id = '".$_GET['id']."' ");
$row=mysqli_fetch_array($query);
?>

<select name="sex" id="opt2">
<option value="">select</option>
<option value="Male" selected="selected">Male</option>
<option value="Female" selected="selected">Female</option>
</select>

Something like this might work.

<?php foreach($row as $reg): ?>
    <select name="sex" id="opt2">
    <option value="">select</option>
    <option value="Male" <?php if($reg['sex'] == 'Male'){echo 'selected="selected"';}?>>Male</option>
    <option value="Female" <?php if($reg['sex'] == 'Female'){echo 'selected="selected"';}?>>Female</option>
    </select>
<?php endforeach; ?>

Thank you...

<select name="state_id" id="states" class="form-control">
<?php 
$sql10= mysql_query("select * from states");
while($row10 = mysql_fetch_array($sql10)){
?>
<!-------------------------------edit-code----------------------------->
<option value="<?php echo $row10['state_id']; ?>"
<?php 
if(($row7['state_id'] == $row10['state_id'])){
echo 'selected = "selected"';
} ?>>
<?php echo $row10['state_name']; ?></option>
<?php
}
?>
</select>
<select name="yr">
<?php 
for($i=2005;$i<=date('Y');$i++){ ?>
?>
<!-------------------------------edit-code----------------------------->
<option value="<?php echo $row1['year1']; ?>"
<?php 
if(($row1['year1'] == $i)){
echo 'selected = "selected"';
} ?>>
<?php echo $i; ?></option>
<?php
}
?>
</select>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.