我有一个简单的下拉菜单,它将数据发送到数据库。。
这是代码示例(不是真正的值,只是为了让每个人都了解我的问题(
<div class="card-body">
<form name="Choice" method="get">
<div class="Choice">
<label for="inputStatus">What color are your eyes</label>
<select id="inputStatus" name="EyeColor" class="form-control">
<option value="Brown">My eyes are brown</option>
<option value="Green">My eyes are green</option>
<option value="Blue">My eyes are blue</option>
</select>
</div>
</br>
<div class="row">
<div class="col-12">
<input type="submit" value="<?=$lang['Submit']?>" class="btn btn-info float-right">
</button>
</div>
</div>
</form>
</div>
数据通常发送到数据库,但在我按下提交后,我希望下拉菜单的值保持(显示(在我刚刚选择的菜单中。
<?php
$lastValue="Brown";//mysqli->query
?>
<div class="card-body">
<form name="Choice" method="get">
<div class="Choice">
<label for="inputStatus">What color are your eyes</label>
<select id="inputStatus" name="EyeColor" class="form-control">
<option <?=$lastValue=="Brown":"selected"?> value="Brown">My eyes are brown</option>
<option <?=$lastValue=="Green":"selected"?> value="Green">My eyes are green</option>
<option <?=$lastValue=="Blue":"selected"?> value="Blue">My eyes are blue</option>
</select>
</div>
</br>
<div class="row">
<div class="col-12">
<input type="submit" value="<?=$lang['Submit']?>" class="btn btn-info float-right">
</button>
</div>
</div>
</form>
</div>