首页 > 解决方案 > 第二个单选按钮始终显示在 PHP 中选中

问题描述

我的页面和代码下​​方有单选按钮,我正在使用它。如果我将数据插入数据库,那么它会发送正确的值。

现在,我的问题是,我在编辑页面上,每次,女性单选按钮都显示为选中状态。我不知道为什么。我正在1从数据库中获取价值。

另外,我注意到如果我删除它,isset()那么它可以工作,但我不想删除它。如果我删除isset()然后我在编辑页面上收到错误

注意:尝试访问 bool 类型值的数组偏移量

<?php $info['profile']['gender']=1;?>
  <div class="form-check  ps-0">
        <input type="radio" id="male" class="radio-custom" name="gender" value="1" <?php if(isset($info['profile']['gender'])==1){?> checked="checked" <?php }?>>
        <label for="male" class="radio-custom-label">Male</label>
     </div>
     <div class="form-check">
        <input type="radio" id="female" class="radio-custom" name="gender" value="2" <?php if(isset($info['profile']['gender'])==2){?> checked="checked" <?php }?>>
        <label for="female" class="radio-custom-label">Female</label>
     </div>

标签: phphtmlradio

解决方案


推荐阅读