<?php
$sql = "SELECT id, name FROM cities";
$stmt = $DBcon->prepare($sql);
$stmt->execute();
$cities = $stmt->fetchAll();
$current_city_id = '';
$current_city_id=$cities[0]['id'];
$dropdown = '<select name="city">';
foreach ($cities as $city) {
$selected='';
if ($current_city_id==$city['id']) $selected=" selected";
$dropdown .= '<option value="'.$city['id'].'">' . $city['name'] .'</option>';
}
$dropdown .='</select>';
echo $dropdown;
?>
Selected value is not showing in dropdown then user press update button. Can't find where the problem is.