Reputation: 9
I am using the following script to retrieve data from my mysql db and to fill a dropdown. Retrieving, selecting and submitting are working perfectly. The only thing is that the selected option falls back to the initial option value of the values retrieved. I want the selected value to remain visible until the user changes the selection. I checked several scripts in Stack but could not reach at a solution. Obviously I am missing something in the script but 'what'? Is there anyone that can help me out?
<!-- fetches values from the database -->
<?php
$sql = "SELECT DISTINCT provincie FROM col_erfgoed";
$query = $conn->prepare($sql);
$query->execute();
$option = "";
$result = $query->fetchAll(PDO::FETCH_ASSOC);
foreach ($result as $row) {
$provincie = $row['provincie'];
$option.='<option value="'.$provincie.'">'.$provincie.'</option>';
}
?>
<!-- lists the options in the database -->
<h4>Make a choice from the options</h4>
<form method="post" action="">
<select name="provincie" id="options" class="options">
<?php echo $option?>
</select>
<input type="submit" value="Send" />
</form>
Upvotes: 0
Views: 13