View Full Version : Simple if else logic is failing me

07-03-2010, 06:47 PM
I must be missing something obvious.. trying to make an if, elseif, else statement... can you not do so with $_SESSION vars?

echo '<p>usrLevel is: '.$_SESSION[usrLevel].'</p>'; // this outputs the value 6

echo '<p>userLevel is below or equal to 2</p>';
}elseif(($_SESSION[usrLevel]>2) OR ($_SESSION[usrLevel]<6)){
echo '<p>userLevel is between 2 and 5</p>'; // this is the outputted statement despite the userLevel equalling 6
echo '<p>userLevel is above 5</p>';


usrLevel is: 6

userLevel is between 2 and 5

please educate me.. I clearly am missing the boat or need another cup of coffee.

07-03-2010, 07:01 PM
You're bound checking wrong. OR evaluates to its first true and quits never evaluating the next (TRUE OR FALSE is always true, so there is no need to check the second expression). That should be an &&. Due to presedence, I would recommend always using && and over AND and OR unless its specifically used for the control of ordering.

07-06-2010, 02:52 AM
What is your
error_reporting() set to? It might be caused by unquoted array elements: $somearray[notagoodwaytofetchavalue]. Array elements should be quotes, as PHP will treat unquoted array keys as constants.

So, try fixing this: