Take the 2-minute tour ×

Possible Duplicate:
Php $_GET method

when I enter this link


I get this error and i don't know why:

Unknown column '9BYELZ0WxdQr4An' in 'where clause'

Here is the code:

$sql = "SELECT * FROM chat WHERE chat_members_code = " . mysql_real_escape_string($_GET['chat_members_code']);
$chat = mysql_query($sql);
if(!$chat) {
echo mysql_error();
}else {

while($row = mysql_fetch_array($chat)) {

$chat_id = $row['id'];
$user_1_id = $row['user_1_id'];
$user_1_fullname = $row['user_1_fullname'];
$user_1_username = $row['user_1_username'];
$user_2_id = $row['user_2_id'];
$user_2_fullname = $row['user_2_fullname'];
$user_2_username = $row['user_2_username'];
$chat_body = $row['chat_body'];
$chat_members_code = $row['chat_members_code'];
$chat_time = $row['chat_time'];
$chat_date = $row['chat_date'];
$chat_datetime = $row['chat_datetime'];

do anyone know where is th error?

share|improve this question

marked as duplicate by mario, tereško, hjpotter92, TemplateRex, Jan Hančič Feb 3 '13 at 8:41


The quotes, they are useful to delimit a string. –  raina77ow Feb 2 '13 at 22:23
You are using an obsolete database API and should use a modern replacement. –  Quentin Feb 2 '13 at 22:24

1 Answer 1

You forgot to wrap your value in quotes:

$sql = "SELECT * FROM chat WHERE chat_members_code = '" . mysql_real_escape_string($_GET['chat_members_code']) . "'";
share|improve this answer
This kind of mistake demonstrates why mysql_query should not be used in new application code. It's just too easy to get wrong. –  tadman Feb 2 '13 at 22:42
