Forum Moderators: coopster

Message Too Old, No Replies

What does 'unknown column in where clause' mean?

Error message when trying to use WHERE statement

         

s9901470

7:49 pm on Feb 21, 2005 (gmt 0)

10+ Year Member



Hi

When using PHP/MySQL to check a username and password in a database, I get this error message:

Unknown column 'username' in 'where clause'

Here is my code:

<?php
$sql = "select * from members where user=$user and pw=$pw";
$result = mysql_query($sql) or die(mysql_error());
$num = mysql_nuw_rows($result);
echo $num;
if($num <= 0 )
{
echo 'There is noone in the database with that name and password';
}
else
{echo 'The username and password match';}
?>

Any suggestions?

jatar_k

7:55 pm on Feb 21, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



that column doesn't exist in the table you are trying to query or is maybe spelled incorrectly.

s9901470

8:09 pm on Feb 21, 2005 (gmt 0)

10+ Year Member



It does exist, are 'user' or 'pw' perhaps reserved words?

jatar_k

8:42 pm on Feb 21, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



well the error says

Unknown column 'username' in 'where clause'

but I don't see 'username' in the query you posted. Could it be from somewhere other than that line?

s9901470

9:19 pm on Feb 21, 2005 (gmt 0)

10+ Year Member



Think that's it, many thanks