我想使用PHP脚本检查并取消选中我的表单的复选框

Abh*_*bhi 1 php

嗨,大家好我想检查并取消选中我的表单的复选框使用PHP脚本.在数据库中我使用数据类型TinyInt存储0或1.我使用以下代码.

<tr>
    <td><div id="formEditProfileLblAEmail">Allow Email</div> 
    </td><td><input type="checkbox" checked="<?php

$sql = "Select firstname,middlename,lastname,nickname,require_email,allow_scores from user_info where username = '".$_SESSION['username']."'";
  $result=mysql_query($sql);
  $count=mysql_num_rows($result);
  $row = mysql_fetch_array($result); 


          if($count>0)
          {

             if($row['require_email']=='1')
              {
                 echo 'checked';
              }
              else
              {
                 echo 'unchecked';
              }
          }
          else
              echo 'unchecked';

          ?>" name="formEditProfileChkAEmail"  id="formEditProfileChkAEmail" /> </td></tr>
Run Code Online (Sandbox Code Playgroud)

但是我的复选框总是会被检查我是否在数据库中有0或1.

Sha*_*ngh 5

如果只是添加内部if,请不要使用else部分

删除checked="if之外的那个

<input type="checkbox" 
<?php if($row['require_email']=='1')  {
                 echo 'checked="checked"';
 }
Run Code Online (Sandbox Code Playgroud)

与您希望取消选中的复选框无关.