此代码应将 selected=selected 回显到相关选项,但它没有将所选值显示为突出显示,或在源代码中显示 selected=selected。
<?php
try {
$stmt = $conn->prepare("SELECT * FROM customer_info WHERE user_id = :user_id");
$stmt->bindValue(':user_id', $user_id);
$stmt->execute();
}catch(PDOException $e) {echo $e->getMessage();}
$row = $stmt->fetch();
?>
<select name="gift_privacy">
<option value="Standard" <?php if($row['gift_privacy']=='Standard') echo "selected='selected'"; ?>>Standard</option>
<option value="Gift ID Req" <?php if($row['gift_privacy']=='Gift_ID_Req') echo "selected='selected'"; ?>>Require program ID</option>
<option value="Not Enrolled" <?php if($row['gift_privacy']=='Not_Enrolled') echo </select>
结果var_dump($row);
:
["gift_privacy"]=> string(12) "Not Enrolled"
源代码
<select name="gift_privacy" style="width:12em;">
<option value="Standard" >Standard</option>
<option value="Gift ID Req" >Require program ID</option>
<option value="Not Enrolled" >Do not enroll</option>
</select>