Php $ _GET方法

时间:2013-02-02 21:52:08

标签: php mysql

  

可能重复:
  mysql_fetch_array() expects parameter 1 to be resource, boolean given in select

如何使php获取字母和数字例如
http://www.mywebsite.com/chatBody.php?chat_code=9BYELZ0WxdQr4An

我是我正在使用的所有代码:

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

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

}

显示此错误:

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\LiveChat\php\chatBody.php on line 21

1 个答案:

答案 0 :(得分:0)

试试这个

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