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.

Community
  • 1
  • 1
Steveep
  • 25
  • 6

2 Answers2

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;
}
Blake A. Nichols
  • 870
  • 1
  • 6
  • 11
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.

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149