1

I have a problem similar to the post:

how to check multiple $_POST variable for existence using isset()?

My issue is, I have a rather large list of checkboxes I need to know if they were checked in order to set the status of $row. it would be exactly like the mentioned script,all and's, except I have and OR thrown in to the works.

if (  isset($_POST['Facial1']) 
    && ($_POST['Facial2']) 
    && ($_POST['Facial3'])
    && ($_POST['Facial4']) 
    && ($_POST['Intra-Oral1']) 
    && ($_POST['Intra-Oral2'])
    && ($_POST['Intra-Oral3']) 
    && ($_POST['Intra-Oral4']) 
    && ($_POST['Intra-Oral5']) 
    && ($_POST['Intra-Oral6']) 
    && (
         (
             ($_POST['X-Ray1']) 
          && ($_POST['X-Ray3'])
         ) 
        || ($_POST['X-Ray5'])
       )
   )
{
    $Status = 1; 
} else {
    $Status = 0;
}

Each time I run a test, as soon as it gets to an element that is not checked it throws an error: undefined index: xxx. Where xxx is the first none checked item.

2 Answers 2

1

Checkboxes that are not checked do not get sent as part of the POST body. Your code needs to use isset:

if (  isset($_POST['Facial1']) 
&& isset($_POST['Facial2']) 
&& isset($_POST['Facial3'])
&& isset($_POST['Facial4']) 
&& isset($_POST['Intra-Oral1']) 
&& isset($_POST['Intra-Oral2'])
&& isset($_POST['Intra-Oral3']) 
&& isset($_POST['Intra-Oral4']) 
&& isset($_POST['Intra-Oral5']) 
&& isset($_POST['Intra-Oral6']) 
&& (
     (
         isset($_POST['X-Ray1']) 
          && isset($_POST['X-Ray3'])
         ) 
        || isset($_POST['X-Ray5'])
       )
   )
{
    $Status = 1; 
} else {
    $Status = 0;
}
Sign up to request clarification or add additional context in comments.

Comments

1

the isset() allows you to check one variable isset($var) or multiple variables at a time isset($var,$var1,$var2) this will return true is all exists and false if one or more are not set.

Your code is only checking one and then doing well I am not sure what

Try

if (  isset(
            $_POST['Facial1'], $_POST['Facial2'], $_POST['Facial3'],
            $_POST['Facial4'], $_POST['Intra-Oral1'], $_POST['Intra-Oral2']
            $_POST['Intra-Oral3'], $_POST['Intra-Oral4'], 
            $_POST['Intra-Oral5'], $_POST['Intra-Oral6']
            )
      &&
        ( 
          isset($_POST['X-Ray1'], $_POST['X-Ray3'])
          || 
          isset($_POST['X-Ray5'])
        )
   )
{
    $Status = 1; 
} else {
    $Status = 0;
}

I hope this is what you intended, its not totally obvious from your code.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.