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 4 of 4

Thread: Help!!!

  1. #1
    Regular Coder
    Join Date
    Sep 2002
    Location
    Scotland
    Posts
    407
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Help!!!

    Any ideas what i'm doing wrong...
    I fire this at the mySQL database (from a php script):

    SELECT * FROM users WHERE username=sweenster

    and i get no response.

    i've tried:

    SELECT * FROM users WHERE username like 'sweenster'

    as well and it still aint workin.

    My body's a temple... and like those ancient Greek ones it's a ruin
    sweenster.co.uk

  • #2
    New Coder
    Join Date
    Aug 2002
    Location
    Cape Town, South Africa
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The sql looks correct to me. The only prob I can see with the first query is that perhaps it should be:

    SELECT * FROM users where username='sweenster';

    but then again, the latter query:

    SELECT * FROM users WHERE username LIKE 'sweenster';

    is (as far as I can tell) 100% correct. So perhaps it is a problem with the table or column name. What error does it complain about?

  • #3
    Regular Coder
    Join Date
    Sep 2002
    Location
    Scotland
    Posts
    407
    Thanks
    0
    Thanked 0 Times in 0 Posts
    well my web host has a built in sql-maintainance program which i also tried using.

    I put the first request in and got the response:
    "unknown column 'sweenster'"

    mind you, the query itself is defined as:

    $query = "SELECT * FROM users WHERE username=".$user."";

    where $user is referred from the login page
    maybe this helps??
    My body's a temple... and like those ancient Greek ones it's a ruin
    sweenster.co.uk

  • #4
    New Coder
    Join Date
    Aug 2002
    Location
    Cape Town, South Africa
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The reason you get the "unknown column 'sweenster'" error is because it is not in single quotes so mysql tries to treat it like a column name but since there is no column name, sweenster in table users it complains.

    This should fix your problem:

    $query = "SELECT * FROM users WHERE username=\"$user\"";

    EXPLANATION:
    You have to escape, the quotation marks, otherwise php will treat it as the end of a string which it recognises as a set of charachters enclosed in quotes.

    The dot operator acts as a string concatanator and joins two or more strings together.

    Fixing these two aspects (as in the code above) should correct the problem.


  •  

    Posting Permissions

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