Jump to content

Recommended Posts

Hi guys,

 

I guess this is a really easy thing to solve but im new to coding and being quite dumb..

 

I want to put and If statement with 2 variables, without using ElseIf.

 

Here is what i mean:

 

if ($_REQUEST["firstname"]=="") AND ($_REQUEST["lastname"]=="") {
  echo "Write Your Name!";
} else {
  echo "Hello";
}

 

I cant figure out the AND bit. I realise the whole IF has to be in brackets but cant find the syntax for the AND in the middle :(

 

Please help!

 

Joe

Link to comment
https://forums.phpfreaks.com/topic/131279-solved-if-statement/
Share on other sites

1) This has absolutely nothing to do with math. Topic was moved.

 

2) Don't use $_REQUEST; use $_GET or $_POST instead, depending on what you're actually looking for.

 

3) Try this (note the parens surrounding the WHOLE if statement):

if (($_POST['firstname'] == "") && ($_POST['lastname'] == "")) {
...............

 

4) && is nicer than AND, imo. xD

Link to comment
https://forums.phpfreaks.com/topic/131279-solved-if-statement/#findComment-681626
Share on other sites

It's not just a matter of niceness, AND/&& and OR/|| have different operator precedent values.

 

"blah or die (xxx)" is not the equivalent of "blah || die(xxx)"

 

It's the same for that case, I believe, but it can affect things sometimes.

 

You've just got to have the last say don't you?

Link to comment
https://forums.phpfreaks.com/topic/131279-solved-if-statement/#findComment-681726
Share on other sites

It's not just a matter of niceness, AND/&& and OR/|| have different operator precedent values.

 

"blah or die (xxx)" is not the equivalent of "blah || die(xxx)"

 

It's the same for that case, I believe, but it can affect things sometimes.

 

You've just got to have the last say don't you?

 

What?  I was saying that it didn't really matter in that particular instance.  I mean, the operator precedence CAN affect things, but not here.  Chill out.

Link to comment
https://forums.phpfreaks.com/topic/131279-solved-if-statement/#findComment-681727
Share on other sites

It's not just a matter of niceness, AND/&& and OR/|| have different operator precedent values.

 

"blah or die (xxx)" is not the equivalent of "blah || die(xxx)"

 

It's the same for that case, I believe, but it can affect things sometimes.

 

The precedences are never the same.

 

The difference may have no effect in some cases, but that is not the same thing.

Link to comment
https://forums.phpfreaks.com/topic/131279-solved-if-statement/#findComment-684200
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.