JoeCullen Posted November 3, 2008 Share Posted November 3, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/131279-solved-if-statement/ Share on other sites More sharing options...
DarkWater Posted November 3, 2008 Share Posted November 3, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/131279-solved-if-statement/#findComment-681626 Share on other sites More sharing options...
Barand Posted November 4, 2008 Share Posted November 4, 2008 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)" Quote Link to comment https://forums.phpfreaks.com/topic/131279-solved-if-statement/#findComment-681668 Share on other sites More sharing options...
DarkWater Posted November 4, 2008 Share Posted November 4, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/131279-solved-if-statement/#findComment-681709 Share on other sites More sharing options...
trq Posted November 4, 2008 Share Posted November 4, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/131279-solved-if-statement/#findComment-681726 Share on other sites More sharing options...
DarkWater Posted November 4, 2008 Share Posted November 4, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/131279-solved-if-statement/#findComment-681727 Share on other sites More sharing options...
DeanWhitehouse Posted November 4, 2008 Share Posted November 4, 2008 Lol, DarkWater you are proving Thorpe right. Btw OP if the topic is solved there is a link at the bottom left. Quote Link to comment https://forums.phpfreaks.com/topic/131279-solved-if-statement/#findComment-681764 Share on other sites More sharing options...
JoeCullen Posted November 6, 2008 Author Share Posted November 6, 2008 Thanks for the help "&&" works great Quote Link to comment https://forums.phpfreaks.com/topic/131279-solved-if-statement/#findComment-684191 Share on other sites More sharing options...
Barand Posted November 6, 2008 Share Posted November 6, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/131279-solved-if-statement/#findComment-684200 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.