Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-03-2010, 05:47 PM   PM User | #1
Bobafart
Regular Coder

 
Join Date: Dec 2006
Posts: 416
Thanks: 168
Thanked 1 Time in 1 Post
Bobafart is on a distinguished road
Simple if else logic is failing me

I must be missing something obvious.. trying to make an if, elseif, else statement... can you not do so with $_SESSION vars?

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

if($_SESSION[usrLevel]<3){
  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
}else{
  echo '<p>userLevel is above 5</p>';
}
?>
Output:

Code:
usrLevel is: 6

userLevel is between 2 and 5
please educate me.. I clearly am missing the boat or need another cup of coffee.
Bobafart is offline   Reply With Quote
Old 07-03-2010, 06:01 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,662
Thanks: 4
Thanked 2,452 Times in 2,421 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Fou-Lu is offline   Reply With Quote
Users who have thanked Fou-Lu for this post:
Bobafart (07-03-2010)
Old 07-06-2010, 01:52 AM   PM User | #3
johnnnn
New Coder

 
Join Date: May 2009
Location: Pennsylvania, United States
Posts: 54
Thanks: 16
Thanked 0 Times in 0 Posts
johnnnn is an unknown quantity at this point
What is your
Code:
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:

PHP Code:
$_SESSION[usrLevel
to

PHP Code:
$_SESSION['usrLevel'
johnnnn is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:40 AM.


Advertisement
Log in to turn off these ads.