Link to home
Start Free TrialLog in
Avatar of MK15
MK15

asked on

php, logic

hi guys,
I have 3 form fields, i need away to find out which field isset, i don't want to be using several if statements to find out which of the 3 fields have text inputted in.  Note, that all 3 may have text in them.  After i find out which ones have been set i can add the data to a database after following certain security phases.
             $email =  $_POST['email'];
              $firstname = $_POST['firstname'];
             $surname = $_POST['surname'];

Open in new window


e.g. of what i am trying to avoid
if((isset($email)) && (isset($firstname))&&(isset($surname))){
                     echo 'here';
              }
              if((isset($email)) && (isset($firstname))){
                     echo 'here';
              }
              
              if((isset($email)) && (isset($surname))){
                     echo 'here';
              }
..........................

Open in new window


thanks in advance guys
Avatar of designatedinitializer
designatedinitializer
Flag of Portugal image

You can iterate the $_POST array BEFORE assigning it to local variables, like this:

foreach($_POST as $field){
      if($field!=''){
             // do your stuff
      }else{
             // do other stuff
      }
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of MK15
MK15

ASKER

mate, that is pretty sweet, never would have thought about doing it that way.  cheers dude
Glad you liked it.!