我有一个性别单选按钮。该值正存储在db中,我也能够获取它。但是我希望检查单选按钮的接收值。救救我。
<input type="radio" name="gender" value="male" > Male
<input type="radio" name="gender" value="female" checked> Female
答案 0 :(得分:0)
您可以按照以下步骤进行操作
<?php
$db_value = 'male'; // this is the value from db
?>
<input type="radio" name="gender" value="male" <?php if($db_value == 'male'):?>checked<?php endif;?>> Male
<input type="radio" name="gender" value="female" <?php if($db_value == 'female'):?>checked<?php endif;?>> Female
答案 1 :(得分:0)
您可以使用radiobutton
来检查应选择哪个if-else statement
,如下所示,其中$row['gender']
是具有单选按钮值的列:
<?php if($row['gender']== 'male') { ?>
<input type="radio" name="gender" value="male" checked> Male
<?php }else { ?>
<input type="radio" name="gender" value="female" checked> Female
<?php } ?>