brob Posted January 24, 2007 Share Posted January 24, 2007 Hi I need to be able to use the OR statement to run a query.[code]if ((!$member) || (!$nonmember)){do what ever}{code]this doesn't work does anyone know why?Thanks[/code] Link to comment https://forums.phpfreaks.com/topic/35498-correct-use-of-the-or-statement/ Share on other sites More sharing options...
HuggieBear Posted January 24, 2007 Share Posted January 24, 2007 Try putting a '$' symbol in front of nonmember...You've missed it out :)RegardsHuggie Link to comment https://forums.phpfreaks.com/topic/35498-correct-use-of-the-or-statement/#findComment-167953 Share on other sites More sharing options...
brob Posted January 24, 2007 Author Share Posted January 24, 2007 sorry I have it in my code I just dont have it in this example Link to comment https://forums.phpfreaks.com/topic/35498-correct-use-of-the-or-statement/#findComment-167955 Share on other sites More sharing options...
HuggieBear Posted January 24, 2007 Share Posted January 24, 2007 OK, what are you trying to achieve?It maybe that !$member isn't actually doing what you think it is.RegardsHuggie Link to comment https://forums.phpfreaks.com/topic/35498-correct-use-of-the-or-statement/#findComment-168036 Share on other sites More sharing options...
brob Posted January 24, 2007 Author Share Posted January 24, 2007 I have two different types of login a member and non member and they are both stored in differnet sessions. $ member and $nonmemberI want to check that if neither is logged in they are thrown back to the login page. Link to comment https://forums.phpfreaks.com/topic/35498-correct-use-of-the-or-statement/#findComment-168038 Share on other sites More sharing options...
HuggieBear Posted January 24, 2007 Share Posted January 24, 2007 In that case you need AND, not OR.[code]<?phpif ((!$member) && (!$nonmember)){ // do whatever}?>[/code]With OR, only one of the sides needs to be true for the whole statement to be true, with AND, both sides need to be true, which is what you're after.RegardsHuggie Link to comment https://forums.phpfreaks.com/topic/35498-correct-use-of-the-or-statement/#findComment-168085 Share on other sites More sharing options...
Psycho Posted January 24, 2007 Share Posted January 24, 2007 Using negative tests with AND's and OR's can be confusing. You could also rewrite it like so:<?phpif ( !($member || $nonmember) ) { // do whatever}?>Using your original logic you are testing wether the person is "not a member" or "not a nonmember". I would assume that both of those can't be true at the same time. Thus, your test will always pass. Link to comment https://forums.phpfreaks.com/topic/35498-correct-use-of-the-or-statement/#findComment-168108 Share on other sites More sharing options...
HuggieBear Posted January 24, 2007 Share Posted January 24, 2007 [quote author=mjdamato link=topic=123806.msg512326#msg512326 date=1169651760]I would assume that both of those can't be true at the same time. Thus, your test will always pass.[/quote]Hence, the change to AND instead of OR :)Huggie Link to comment https://forums.phpfreaks.com/topic/35498-correct-use-of-the-or-statement/#findComment-168113 Share on other sites More sharing options...
Psycho Posted January 24, 2007 Share Posted January 24, 2007 [quote author=HuggieBear link=topic=123806.msg512331#msg512331 date=1169651868][quote author=mjdamato link=topic=123806.msg512326#msg512326 date=1169651760]I would assume that both of those can't be true at the same time. Thus, your test will always pass.[/quote]Hence, the change to AND instead of OR :)[/quote]Yes, absolutely. But, I was just trying to point out that it is confusing because most people don't think along the lines of "is he not a member and not a non member". They usually think along the lines of "is he not (a member or a non member)". That is the problem which the OP ran into, which is why I gave the other method which is more closely associated with how many people usually think.There is nothing inherently right or wrong with either method. I was just giving another option. Link to comment https://forums.phpfreaks.com/topic/35498-correct-use-of-the-or-statement/#findComment-168311 Share on other sites More sharing options...
HuggieBear Posted January 25, 2007 Share Posted January 25, 2007 Fair comment, I wasn't saying that what you'd posted was incorrect. I think it's good that people are prepared to make posts regarding additional methods.RegardsHuggie Link to comment https://forums.phpfreaks.com/topic/35498-correct-use-of-the-or-statement/#findComment-168796 Share on other sites More sharing options...
chriscloyd Posted January 25, 2007 Share Posted January 25, 2007 how about u try$_SESSION['member'] or $_SESSION['nonmember'] Link to comment https://forums.phpfreaks.com/topic/35498-correct-use-of-the-or-statement/#findComment-168807 Share on other sites More sharing options...
HuggieBear Posted January 25, 2007 Share Posted January 25, 2007 [quote author=chriscloyd link=topic=123806.msg513032#msg513032 date=1169718183]$_SESSION['member'] or $_SESSION['nonmember'][/quote]Chris,This is a good point, I had assumed that as the OP had only posted a snippet of code that they had already assigned the session variables to $member or $nonmember.Huggie Link to comment https://forums.phpfreaks.com/topic/35498-correct-use-of-the-or-statement/#findComment-168812 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.