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

Thread: Multiple WHERE

  1. #1
    Regular Coder
    Join Date
    Sep 2006
    Location
    Colorado
    Posts
    132
    Thanks
    7
    Thanked 1 Time in 1 Post

    Multiple WHERE

    I have a query:
    PHP Code:
    $sql "SELECT * FROM notes WHERE uid='$_SESSION[uid]', class='$_GET[class]' ORDER BY time ASC LIMIT 10"
    I want to get everything where the uid is equal to the session variable and the class is equal to the class var in the url... I have no idea whats wrong.
    -bubbles

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Are you getting an error or just no rows? I don't think you can separate your WHERE clauses with a comma, I think you have to use the AND keyword. It's worth a shot anyway.

    And, by the way:
    This is wrong: $_GET[class]
    This is right: $_GET['class']

    PHP Code:
    $sql "SELECT * 
    FROM notes 
    WHERE uid='"
    .$_SESSION['uid']."' 
    AND class='"
    .$_GET['class']."' 
    ORDER BY time ASC 
    LIMIT 10"


  • #3
    Super Moderator guelphdad's Avatar
    Join Date
    Mar 2006
    Location
    St. Catharines, Ontario Canada
    Posts
    2,634
    Thanks
    4
    Thanked 148 Times in 139 Posts
    You can't separate with a comma because the query has no idea that both conditions must be true. Use AND as suggested above.

    Also you should look in the php manual on using mysql_real_escape_string for cleaning up both of your variables. DO NOT accept anything from a form or cookie etc. that you haven't cleaned first.

    if you aren't familiar with it look into sql injection attacks and cross server scripting attacks and see the problems you can run into.


  •  

    Posting Permissions

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