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] Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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'] Quote Link to comment 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 Quote Link to comment 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.