roeyhaim Posted November 3, 2010 Share Posted November 3, 2010 Hello, can anybody tell me whats wrong with my code: function check_login($uname, $pwd){ $sql = "SELECT * FROM users WHERE uname=$uname"; $result = mysql_query($sql) or die('Error, Load query failed: ' . mysql_error()); $data = array(); while($row=mysql_fetch_assoc($result)){ $data[] = $row; } return $data; } $chk = check_login("test", "test1"); foreach($chk as $row){ echo $row['uname']; echo " = "; echo $row['pass']; echo "<BR>"; } when i run this i get: Error, Load query failed: Unknown column 'test' in 'where clause' Link to comment https://forums.phpfreaks.com/topic/217660-mysql-error/ Share on other sites More sharing options...
mikosiko Posted November 3, 2010 Share Posted November 3, 2010 wow.... this is not clear enough? :-\ Error, Load query failed: Unknown column 'test' in 'where clause' hint uname=$uname Link to comment https://forums.phpfreaks.com/topic/217660-mysql-error/#findComment-1129907 Share on other sites More sharing options...
roeyhaim Posted November 3, 2010 Author Share Posted November 3, 2010 Not really. as i see on W3school: SELECT column_name(s) FROM table_name WHERE column_name operator value example: $result = mysql_query("SELECT * FROM Persons WHERE FirstName='Peter'"); and this is exactly what i did. the "uname" is the column and the $uname is the value. Link to comment https://forums.phpfreaks.com/topic/217660-mysql-error/#findComment-1129916 Share on other sites More sharing options...
ras1986 Posted November 3, 2010 Share Posted November 3, 2010 is $uname containing string value? if yes, try '$uname'... and also try putting backslashes to your column name `uname`.... i faced this error before and this fixed it.... Link to comment https://forums.phpfreaks.com/topic/217660-mysql-error/#findComment-1129920 Share on other sites More sharing options...
mikosiko Posted November 3, 2010 Share Posted November 3, 2010 Not really. as i see on W3school: ..... WHERE FirstName='Peter'"); and this is exactly what i did. the "uname" is the column and the $uname is the value. and what is the difference between FirstName = 'Peter' and uname = $uname Link to comment https://forums.phpfreaks.com/topic/217660-mysql-error/#findComment-1129921 Share on other sites More sharing options...
roeyhaim Posted November 3, 2010 Author Share Posted November 3, 2010 Thank you ras1986 it's work Link to comment https://forums.phpfreaks.com/topic/217660-mysql-error/#findComment-1129928 Share on other sites More sharing options...
Pikachu2000 Posted November 3, 2010 Share Posted November 3, 2010 is $uname containing string value? if yes, try '$uname'... and also try putting backslashes to your column name `uname`.... i faced this error before and this fixed it.... You mean backticks, not backslashes . . . Link to comment https://forums.phpfreaks.com/topic/217660-mysql-error/#findComment-1129930 Share on other sites More sharing options...
ras1986 Posted November 3, 2010 Share Posted November 3, 2010 sorry.. my bad.... Link to comment https://forums.phpfreaks.com/topic/217660-mysql-error/#findComment-1129932 Share on other sites More sharing options...
PFMaBiSmAd Posted November 3, 2010 Share Posted November 3, 2010 Also, back-ticks are mysql specific and should be avoided whenever possible. Link to comment https://forums.phpfreaks.com/topic/217660-mysql-error/#findComment-1129935 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.