View Full Version : Help!!!

10-31-2002, 12:22 AM
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.


10-31-2002, 01:38 PM
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?

10-31-2002, 02:41 PM
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??

10-31-2002, 05:17 PM
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\"";

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.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum