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
    New Coder
    Join Date
    Feb 2008
    Posts
    39
    Thanks
    0
    Thanked 1 Time in 1 Post

    Select statement isn't working properly

    I have the following code
    Code:
    //query to find the find out if the player_id exsist in the database
    			$sql = mysql_query("SELECT Player_number FROM players where Player_First_Name like '$first' AND Player_Last_Name like '$second' AND Inactive_player = 1 AND player_email = '$email' or player_email2 = '$email'") or die ("Find Player Number Error: " .mysql_error()); 
    				while($row = mysql_fetch_array($sql))
    				{
    					$playerID = $row['Player_number'];
    					echo $playerID;
    					$username = $playerID;
    					$isError = "3";
    				}
    When I tell it to look for valid information it never goes through the while statement, and i don't get an errors. I know it should go through the while statement but I don't see why it isn't.

  • #2
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    LIKE '$first'

    Even though you are using LIKE it is still looking for an exact match. You need to include at least one wildcard:

    % matches any sequence of characters
    _ will match precisely one character


    so
    PHP Code:
    LIKE '$first%' 
    will match names that begin with the text of $first.

    But I suspect you also need to use brackets ( ) around your ANDs and OR expressions to get the correct logic.
    Last edited by AndrewGSW; 12-08-2012 at 10:30 AM.
    "I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
    Validate your HTML and CSS

  • #3
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    .. probably you need this:

    PHP Code:
    AND (player_email '$email' OR player_email2 '$email'
    but that's just an assumption. (I prefer to capitalize SQL keywords.)
    "I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
    Validate your HTML and CSS


  •  

    Posting Permissions

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