#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2008
    Posts
    51
    Rep Power
    7

    Need help with if else elseif


    Hello,

    can someone tell what I'm doing wrong here?

    I want to change this code (which works as is) :

    PHP Code:
      $join '';
      if (
    $_SESSION['login_rights'] < 4) {
          if (
    $where_is =='') {
              
    $restriction_statement 'WHERE ';
          } else {
              
    $restriction_statement 'AND ';
          }

          
    $restriction_statement .= " tc.rights < '2'";

       if (isset(
    $_SESSION['login_rights']) and $_SESSION['login_rights'] = 2) {
       
    $join " JOIN " $table_user_list " AS table ON (table.field = " $_SESSION['login_field'] . " AND table.user = tc.id)";              
          }
      } else {
          
    $restriction_statement '';
      } 
    to this :

    PHP Code:
     $join '';
      if (
    $_SESSION['login_rights'] < 4) {
          if (
    $where_is =='') {
              
    $restriction_statement 'WHERE ';
          } else {
              
    $restriction_statement 'AND ';
          }

          
    $restriction_statement .= " tc.rights < '2'";

          if (isset(
    $_SESSION['login_rights']) and $_SESSION['login_rights'] = 3) {
       
    $join " JOIN " $table_user_list " AS table ON (table.groupfield = " $_SESSION['login_groupfield'] . " AND table.user = tc.id)";              
          }
          elseif (isset(
    $_SESSION['login_rights']) and $_SESSION['login_rights'] = 2) {
       
    $join " JOIN " $table_user_list " AS table ON (table.field = " $_SESSION['login_field'] . " AND table.user = tc.id)";              
          }
      } else {
          
    $restriction_statement '';
      } 
    It will only read the top most condition, ignoring the "elseif". I know I'm doing something wrong. Can someone help?

    Thanks much in advance!
  2. #2
  3. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,908
    Rep Power
    6352
    You're using = (assignment) instead of == (comparison)
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2008
    Posts
    51
    Rep Power
    7

    Problem Solved


    Okay never mind. I figured it out!

    All I had to do was do this (double equal signs)
    == 3

    and not =3
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2008
    Posts
    51
    Rep Power
    7
    Originally Posted by ManiacDan
    You're using = (assignment) instead of == (comparison)
    Thanks Maniac dan.

    Just reading your reply now!
  8. #5
  9. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    Hi,

    use an IDE, it will recognize typical mistakes like this.
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  10. #6
  11. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2011
    Location
    The Pleiades
    Posts
    300
    Rep Power
    9
    What's the best IDE for PHP? I've currently only got Netbeans.

    Kind regards,

    NM.
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2008
    Posts
    51
    Rep Power
    7
    I was using Geany PHP IDE on Ubuntu.

    But it didn't spot those as errors.
    Would Netbeans do it?...
    Worse yet, maybe I need to learn how to use an IDE.
    Just installed Netbeans ....will try it out.
  14. #8
  15. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2011
    Location
    The Pleiades
    Posts
    300
    Rep Power
    9
    I use Netbeans for Java but I think you can install the PHP plugins.

    Kind regards,

    NM.
  16. #9
  17. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,908
    Rep Power
    6352
    Eclipse PDT is what I use on windows, or geany on linux
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  18. #10
  19. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,316
    Rep Power
    7171
    Since what you wrote isn't syntactically invalid, an IDE may not flag it as an error.

    You should consider using && instead of and, and || instead of or. and and or have very low operator precedence which can lead to some unexpected behavior in certain circumstances.
    PHP FAQ

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around
  20. #11
  21. For POny!
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2012
    Location
    Amsterdam
    Posts
    416
    Rep Power
    115
    netbeans php will flag an assignment within an if clause as a possible error
  22. #12
  23. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2008
    Posts
    51
    Rep Power
    7
    Thanks everybody.

    All very useful knowledge!
  24. #13
  25. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    14
    Rep Power
    0
    i guess you are making some mistake here->try elseif (isset($_SESSION['login_rights']) and $_SESSION['login_rights'] == 2) instead of this elseif (isset($_SESSION['login_rights']) and $_SESSION['login_rights'] = 2)

IMN logo majestic logo threadwatch logo seochat tools logo