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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.