Leao Posted October 19, 2006 Share Posted October 19, 2006 Hi,How do I do multiple if statements? I'm sending some variables from an HTML form to the PHP script below. The script is supposed to check if the 3 variables 'apples', 'pears' and 'bananas' have been received by the form and echo "All the elements are present." If all the elements aren't present the script should echo "ERROR!"Cheers,Leao[code=php:0]<?phpif (isset($_POST['apples']))if (isset($_POST['pears']))if (isset($_POST['bananas'])){echo "All the elements are present.";}else{echo "ERROR!";}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/24495-multiple-if-statements/ Share on other sites More sharing options...
trq Posted October 19, 2006 Share Posted October 19, 2006 [code=php:0]<?phpif (isset($_POST['apples']) && isset($_POST['pears']) && isset($_POST['bananas'])) { echo "All the elements are present.";} else { echo "ERROR!";}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/24495-multiple-if-statements/#findComment-111583 Share on other sites More sharing options...
ToonMariner Posted October 19, 2006 Share Posted October 19, 2006 [code]<?phpif (isset($_POST['apples'],$_POST['pears'],$_POST['bananas'])) { echo "All the elements are present.";} else { echo "ERROR!";}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/24495-multiple-if-statements/#findComment-111585 Share on other sites More sharing options...
trq Posted October 19, 2006 Share Posted October 19, 2006 Damn... I always foget isset can except multiple args. Quote Link to comment https://forums.phpfreaks.com/topic/24495-multiple-if-statements/#findComment-111586 Share on other sites More sharing options...
ToonMariner Posted October 19, 2006 Share Posted October 19, 2006 LOL.I always try it empty... then trash myself to within an inch of my life for not remembering for the millionth time that you can't!!!!!One think to note though is that even if a variable is NULL (or empty) isset will return true (except checkboxes and radio buttons) - so if you are looking to make sure that all these variables actually have values use thorpes firts structure replacing isset with !empty Quote Link to comment https://forums.phpfreaks.com/topic/24495-multiple-if-statements/#findComment-111587 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.