kratsg Posted September 2, 2009 Share Posted September 2, 2009 I'm taking an input from the URL $_GET['do'] which contains one of two values: "approve" or "deny" If $_GET['do'] is set to a value that is not either one of these, I'll have it display an error, so I wrote the following conditional: if($_GET['do'] != 'approve' || $_GET['do'] != 'deny') //display error (which also ends the script with a die function //else continue along However, $_GET['do'] as either 'approve' or 'deny' seems to trigger this error, so I did a var_dump var_dump(($_GET['do'] == 'approve' || $_GET['do'] == 'deny')); This returned true if I picked either approve or deny, but false for all others. So I've determined that it has something to do with the "!=" portion... yet for some reason, I can't imagine what's wrong with that... seeing how it should work fine. Any ideas or shall I have to do the if(!($_GET['do'] == 'approve' || $_GET['do'] == 'deny')) instead? Quote Link to comment https://forums.phpfreaks.com/topic/172846-solved-ive-lost-my-mind-over-a-simple-one-line-conditional/ Share on other sites More sharing options...
trq Posted September 2, 2009 Share Posted September 2, 2009 I would look at triming $_GET['do']. Sometimes you get spaces through post / get. Quote Link to comment https://forums.phpfreaks.com/topic/172846-solved-ive-lost-my-mind-over-a-simple-one-line-conditional/#findComment-910972 Share on other sites More sharing options...
kratsg Posted September 2, 2009 Author Share Posted September 2, 2009 I would look at triming $_GET['do']. Sometimes you get spaces through post / get. Done that, even hard-coded $_GET['do'] into the script and then checked the output... maybe I've stared at the code for too long? var_dump($_GET['do']) in all cases returns string(7) "approve" or string(4) "deny" var_dump("approve") returns string(7) "approve" var_dump("deny") returns string(4) "deny" I must be missing something E_E Quote Link to comment https://forums.phpfreaks.com/topic/172846-solved-ive-lost-my-mind-over-a-simple-one-line-conditional/#findComment-910974 Share on other sites More sharing options...
mikesta707 Posted September 2, 2009 Share Posted September 2, 2009 its because that if statement will always run true. You have to test if it is not equal to one AND not equal to the other, not if its not equal to one OR the other if($_GET['do'] != 'approve' && $_GET['do'] != 'deny') with the way you had it, if its approve, the first test will be false, but the second true, and vice versa for deny Quote Link to comment https://forums.phpfreaks.com/topic/172846-solved-ive-lost-my-mind-over-a-simple-one-line-conditional/#findComment-910975 Share on other sites More sharing options...
trq Posted September 2, 2009 Share Posted September 2, 2009 if($_GET['do'] != 'approve' && $_GET['do'] != 'deny') Quote Link to comment https://forums.phpfreaks.com/topic/172846-solved-ive-lost-my-mind-over-a-simple-one-line-conditional/#findComment-910977 Share on other sites More sharing options...
kratsg Posted September 2, 2009 Author Share Posted September 2, 2009 Rawr! I knew I was missing something. I'm forgetting basic logic.... stupid me :-D Thanks! IE: If (P OR Q) then negation is If (not P AND not Q).. Thanks guys. Just had a mind-freeze for a couple minutes there. Quote Link to comment https://forums.phpfreaks.com/topic/172846-solved-ive-lost-my-mind-over-a-simple-one-line-conditional/#findComment-910983 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.