简体   繁体   中英

Check Uncheck in PHP Form

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

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();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM