Jump to content

Multiple if statements?


Leao

Recommended Posts

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]<?php
if (isset($_POST['apples']))
if (isset($_POST['pears']))
if (isset($_POST['bananas']))
{echo "All the elements are present.";}

else
{echo "ERROR!";}
?>[/code]
Link to comment
Share on other sites

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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.