zartzar Posted April 27, 2009 Share Posted April 27, 2009 This is my code if (empty($_POST['fname'])) It works great but i also want to check "lname", "number" ...all the fields. I tried using OR* but it doesn't work * maybe my syntax is wrong?: if (empty($_POST['fname'])) OR (empty($_POST['lname'])) Please help! Quote Link to comment https://forums.phpfreaks.com/topic/155906-solved-check-multiples-variables-with-if/ Share on other sites More sharing options...
wildteen88 Posted April 27, 2009 Share Posted April 27, 2009 Correct syntax if (empty($_POST['fname']) || empty($_POST['lname']) || empty($_POST['number'])) Quote Link to comment https://forums.phpfreaks.com/topic/155906-solved-check-multiples-variables-with-if/#findComment-820670 Share on other sites More sharing options...
zartzar Posted April 27, 2009 Author Share Posted April 27, 2009 Correct syntax if (empty($_POST['fname']) || empty($_POST['lname']) || empty($_POST['number'])) Thx! Another thing, i was wondering, if i had like a hundred fields is there a function that could check them all? Quote Link to comment https://forums.phpfreaks.com/topic/155906-solved-check-multiples-variables-with-if/#findComment-820678 Share on other sites More sharing options...
premiso Posted April 27, 2009 Share Posted April 27, 2009 foreach ($_POST as $key => $val) { if (empty($_POST[$key])) { echo "{$key} was empty."; } } What might be better is to store the names of the fields you want to check in an array then use an in_array condition in the foreach loop above and check only the values you want to check. Quote Link to comment https://forums.phpfreaks.com/topic/155906-solved-check-multiples-variables-with-if/#findComment-820681 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.