mercredi 19 août 2015

Multiple checkbox validation before sql insert

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.




Aucun commentaire:

Enregistrer un commentaire