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 Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.