Jump to content

[SOLVED] I've done this a 1000s of times but nows theres an erroe. Mysql SELECT Problem


paulman888888

Recommended Posts

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

'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.

 

Archived

This topic is now archived and is closed to further replies.

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