2013-02-02 81 views
-2

Possible Duplicate:
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

該代碼不顯示此錯誤。顯示整個代碼 –

+5

[**請不要在新代碼中使用'mysql_ *'函數**](http://bit.ly/phpmsql)。他們不再被維護[並且被正式棄用](http://j.mp/XqV7Lp)。看到[**紅框**](http://j.mp/Te9zIL)?學習[*準備的語句*](http://j.mp/T9hLWi),並使用[PDO](http://php.net/pdo)或[MySQLi](http://php.net/ mysqli) - [這篇文章](http://j.mp/QEx8IB)將幫助你決定哪個。如果你選擇PDO,[這裏是一個很好的教程](http://j.mp/PoWehJ)。 – thaJeztah

+0

連接錯誤 –

回答

0

試試

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

是的,它的作品謝謝你:* –

+0

你可以失去雙重問號。 $ sql =「SELECT * FROM chat WHERE chat_members_code ='$ chatCode'; –