PHP $ _GET方法URL

时间:2013-02-02 22:22:22

标签: php mysql

  

可能重复:
  Php $_GET method

当我输入此链接时

http://www.LiveChat.com/php/chatBody.php?chat_members_code=9BYELZ0WxdQr4An

我收到此错误,我不知道原因:

Unknown column '9BYELZ0WxdQr4An' in 'where clause'

以下是代码:

$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'];
}
}

有谁知道这是错误在哪里?

1 个答案:

答案 0 :(得分:5)

你忘了用引号包装你的价值:

$sql = "SELECT * FROM chat WHERE chat_members_code = '" . mysql_real_escape_string($_GET['chat_members_code']) . "'";