Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Dec 2006
    Posts
    417
    Thanks
    168
    Thanked 1 Time in 1 Post

    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.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    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.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • Users who have thanked Fou-Lu for this post:

    Bobafart (07-03-2010)

  • #3
    New Coder
    Join Date
    May 2009
    Location
    Pennsylvania, United States
    Posts
    54
    Thanks
    16
    Thanked 0 Times in 0 Posts
    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'


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •