checking multiple variables with an if statement

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
malloy
Forum Newbie
Posts: 15
Joined: Fri Jun 01, 2007 2:02 am
Location: Melbourne, Australia

checking multiple variables with an if statement

Post by malloy »

Hi all,

Thanks to all the previous members who have assisted me. I try not to post on here until I have exhausted all other avenues.

Just wondering if there is a way to check if multiple variables are blank.

The example below works for 1 variable but when I specify a second variable 'dob' i get the following error.
Parse error: syntax error, unexpected ',', expecting ')'
which refers to the code below.
I have tried using || to separate the variables too.

Code: Select all

if (empty($_POST['name'], $_POST['dob'])){
echo 'Please fill in all required fields';
}
else {
mail($sendTo, $subject, $headers);
    header("Location: success.php");
}
Any suggestions or links to relevent manual pages would be great.

Kind regards,

malloy
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Code: Select all

if ( empty($_POST['name']) || empty($_POST['dob']) )
malloy
Forum Newbie
Posts: 15
Joined: Fri Jun 01, 2007 2:02 am
Location: Melbourne, Australia

Post by malloy »

Thank you very much volka, worked a treat :)
Post Reply