paulman888888 Posted May 28, 2009 Share Posted May 28, 2009 hi; i have used MySQql for ages but i am now getting strange results, Heres my code; <?php $username=no_slashs(strtolower($_REQUEST['user_name'])); $q=mysql_query('SELECT * FROM `chess_users` WHERE `username`=`'.$username.'`', $link_chess)or die(mysql_error()); if((int)mysql_num_rows($q)>0){echo "no"; }else{ echo "yes"; } $show=0; ?> What i was trying to do is see if there is any usernames with the value of $username but for some reason when i test my script like this; page.php?user_name=bob i get this error; Unknown column 'bob' in 'where clause' i though it goes like this WHERE `colounm`= `value` Please help as this is starting to annoy me Thankyou Paul Link to comment https://forums.phpfreaks.com/topic/160069-solved-ive-done-this-a-1000s-of-times-but-nows-theres-an-erroe-mysql-select-problem/ Share on other sites More sharing options...
kickstart Posted May 28, 2009 Share Posted May 28, 2009 Hi Why have you got back ticks around the inverted commas around the variable? All the best Keith Link to comment https://forums.phpfreaks.com/topic/160069-solved-ive-done-this-a-1000s-of-times-but-nows-theres-an-erroe-mysql-select-problem/#findComment-844440 Share on other sites More sharing options...
paulman888888 Posted May 28, 2009 Author Share Posted May 28, 2009 i got told it was good practise. So what back ticks should i remove? Thankyou Paul Link to comment https://forums.phpfreaks.com/topic/160069-solved-ive-done-this-a-1000s-of-times-but-nows-theres-an-erroe-mysql-select-problem/#findComment-844442 Share on other sites More sharing options...
corbin Posted May 28, 2009 Share Posted May 28, 2009 'SELECT * FROM `chess_users` WHERE `username`=`'.$username.'`' That will make a query that looks like SELECT * FROM `chess_users` WHERE `username` = `corbin` ` is put around MySQL objects (databases, tables, columns... so on). It should look like: That will make a query that looks like SELECT * FROM `chess_users` WHERE `username` = 'corbin' So: $q=mysql_query("SELECT * FROM chess_users WHERE username= '{$username}'", $link_chess) or die(mysql_error()); You may notice I took out all of the backticks. Backticks are native only to MySQL, so for portability and what not, backticks are bad. They're also useless unless the object's name is reserved, and you shouldn't be using reserved names. Link to comment https://forums.phpfreaks.com/topic/160069-solved-ive-done-this-a-1000s-of-times-but-nows-theres-an-erroe-mysql-select-problem/#findComment-844446 Share on other sites More sharing options...
paulman888888 Posted May 28, 2009 Author Share Posted May 28, 2009 Thankyou so much corbin & kickstart Great help Thanks again it all works now thankyou Paul Link to comment https://forums.phpfreaks.com/topic/160069-solved-ive-done-this-a-1000s-of-times-but-nows-theres-an-erroe-mysql-select-problem/#findComment-844453 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.