Jump to content

[SOLVED] The results of IF statement with AND or OR


AndieB

Recommended Posts

Hi all,

 

I'm writing a script which will analyse the POST from a URL. It will check for the $_GET variable. Now, there are two strings or what you can call them that MUST both contain a value each in order to proceed with the script.

 

The URL looks like this: activate.php?e=value?cc=value

 

Now, I started to type the IF statement, but got confused in my mind on HOW I should write it.

Which of my two examples below, actually do what I request... BOTH "strings" should each contain a value.

if (!isset($_GET["e"]) AND !isset($_GET["cc"])) { send to an error page } else { proceed... }

 

OR this one:

if (!isset($_GET["e"]) OR !isset($_GET["cc"])) { send to an error page } else { procced... }

 

Anyone who can clear up my confused mind? :)

 

Thank you in advance for any kind of help!

 

Sincerely,

Andreas

 

 

Basically you will use this one:

if (!isset($_GET["e"]) AND !isset($_GET["cc"])) { send to an error page } else { proceed... }

 

as you want "BOTH" variables to contain a value.

 

 

If you use this:

if (!isset($_GET["e"]) OR !isset($_GET["cc"])) { send to an error page } else { procced... }

 

You will tell PHP that at least one variable can be left without value, which is not what you want. Same if you tell someone to pick between "red OR blue"...you have to select only one.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.