0
good morning. I have a problem here, when I will update a page with data coming from the database the select option shows the data correctly but the captured values are not correct, an example, if it is of cities comes in value only the first name of the city while in the display of the name comes complete, so when I do the update only records the first name, because this dividing and creating fields. what I need is that on the update page the select option comes with the data that is in the database.
<select class="form-control" name="cidade">
<option value="">-- Selecionar --</option>
<?php
$curc4 = $pdo->query("SELECT * FROM comarca ORDER BY comarc asc");
while ($lic4 = $curc4->fetch(PDO::FETCH_ASSOC)) {
echo "<option value=".$lic4['comarc']." ".($cidade == $lic4['comarc'] ? "selected":"")." >".$lic4['comarc']."</option>";
} ?>
</select>
//solução encontrada
<select class="form-control" name="cidag">
<option value="">-- Selecionar --</option>
<?php
$curc4 = $pdo->query("SELECT * FROM comarca ORDER BY comarc asc");
while ($lic4 = $curc4->fetch(PDO::FETCH_ASSOC)) {
$comarc=$lic4['comarc'];
if($cidag == $comarc){
$selected = "selected";
} else {
$selected = " ";
}
?>
<option value="<?php echo $comarc;?>" <?php echo $selected;?> ><?php echo $comarc;?></option>
<?php } ?>
</select>
console shows this way
<option value="ANGRA" dos="" reis="">ANGRA DOS REIS</option>
I thank you for your help
https://answall.com/help/someone-answers
– user60252