douyanqu9722 2019-05-01 18:11
浏览 37
已采纳

选中以PHP表单取消选中

I tried:

<?php
if(isset($_POST['submit']))
{
    echo $_POST['Privilege_Question_Name'];
    $Privilege_Question_Query = (($_POST['Privilege_Question_Name'] == "Privilege_Question_Value") ? 'Y' : 'N');
    echo $Privilege_Question_Query;
    exit();
}
?>

<form method="post"  action="" >
    <span class="float-right">Question Settings&nbsp;&nbsp;
    <input type="checkbox" name="Privilege_Question_Name" id="Privilege_Question_Id" value="Privilege_Question_Value"/></span>
    <br />
    <input type="submit" class="btn btn-lg btn-info" name="submit" value="Submit">
</form>

If the form is checked, it works properly. But if the form is not checked then there's a notice:

Notice: Undefined index: Privilege_Question_Name

  • 写回答

1条回答 默认 最新

  • duanrongpai9556 2019-05-01 18:15
    关注

    An unchecked checkbox will never be sent in the first place, so check if it's set instead.

    if (isset($_POST['submit'])) {
        $Privilege_Question_Query = isset($_POST['Privilege_Question_Name']) ? 'Y' : 'N';
        echo $Privilege_Question_Query;
        exit();
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?