lange513 Posted August 11, 2010 Share Posted August 11, 2010 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 https://forums.phpfreaks.com/topic/210482-unknown-column-when-im-sure-the-column-exists/ Share on other sites More sharing options...
PFMaBiSmAd Posted August 11, 2010 Share Posted August 11, 2010 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 https://forums.phpfreaks.com/topic/210482-unknown-column-when-im-sure-the-column-exists/#findComment-1098258 Share on other sites More sharing options...
lange513 Posted August 11, 2010 Author Share Posted August 11, 2010 Yeah, unless I'm blind it's in the database exactly like that. See the attached file, I just took a screenshot. [attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/210482-unknown-column-when-im-sure-the-column-exists/#findComment-1098259 Share on other sites More sharing options...
PFMaBiSmAd Posted August 11, 2010 Share Posted August 11, 2010 You probably have some white-space/non-printing character (tab, space, cr, lf, ...) either in the column name or in the query. Link to comment https://forums.phpfreaks.com/topic/210482-unknown-column-when-im-sure-the-column-exists/#findComment-1098261 Share on other sites More sharing options...
jdavidbakr Posted August 12, 2010 Share Posted August 12, 2010 What is the output of 'show create table users'? Link to comment https://forums.phpfreaks.com/topic/210482-unknown-column-when-im-sure-the-column-exists/#findComment-1098497 Share on other sites More sharing options...
Pikachu2000 Posted August 13, 2010 Share Posted August 13, 2010 Echo the query to the screen, then paste it into phpMyAdmin and see what result you get. Link to comment https://forums.phpfreaks.com/topic/210482-unknown-column-when-im-sure-the-column-exists/#findComment-1098892 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.