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

Link to comment
Share on other sites

'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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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