Jump to content

"Unknown column" when I'm sure the column exists


lange513

Recommended Posts

I'm getting this error with my simple login system:

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in

 

My code then looked like this:

if ($_POST['Submit'] && $_POST['username'] && $_POST['password']){
$username = $_POST['username'];
$password = $_POST['password'];

$sql="SELECT * FROM users WHERE username='$username' and password='$password'";
$result=mysql_query($sql);

$count=mysql_num_rows($result);

if($count==1){
	$_SESSION['username'] = $username;
	header("location:main.php");
}else {
	echo "Wrong Username or Password";
}
}

 

I then edited my $result line to this:

$result=mysql_query($sql)or die (mysql_error());

 

And got this result:

Unknown column 'password' in 'where clause'

 

The column "password" does exist, so I have no clue what's causing this. Can you help me?

Yes, but does it exist in that database, that table, with that spelling, and with that capitalization (assuming you are on an operating system that is case-sensitive.)

 

You wouldn't be getting that error if mysql found the column you referenced in the query.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.