-2

Possible Duplicate:
mysql_fetch_array() expects parameter 1 to be resource, boolean given in select

How to make php to get letters and numbers for example
http://www.mywebsite.com/chatBody.php?chat_code=9BYELZ0WxdQr4An

I is the all code I'am useing:

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

}

It shows this error:

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\LiveChat\php\chatBody.php on line 21
Community
  • 1
  • 1
  • 1
    That code does not show this error. Show the whole code – Shiplu Mokaddim Feb 02 '13 at 21:54
  • 5
    [**Please, don't use `mysql_*` functions in new code**](http://bit.ly/phpmsql). They are no longer maintained [and are officially deprecated](http://j.mp/XqV7Lp). See the [**red box**](http://j.mp/Te9zIL)? Learn about [*prepared statements*](http://j.mp/T9hLWi) instead, and use [PDO](http://php.net/pdo) or [MySQLi](http://php.net/mysqli) - [this article](http://j.mp/QEx8IB) will help you decide which. If you choose PDO, [here is a good tutorial](http://j.mp/PoWehJ). – thaJeztah Feb 02 '13 at 21:55
  • `mysql_error()` will inform you about the missing string quotes. -- Also please write less shallow question titles. – mario Feb 02 '13 at 21:59
  • please i need an answer the error is in mysql_real_escape_string() – Maroon Saed Feb 02 '13 at 22:04
  • It's here: http://stackoverflow.com/a/11674313/250259 – John Conde Feb 02 '13 at 22:05
  • `mysql_query` will be removed in future versions of PHP. If you don't switch to something more modern like [PDO](http://net.tutsplus.com/tutorials/php/why-you-should-be-using-phps-pdo-for-database-access/) now, you'll have to switch to it later when your application stops working and the amount of work involved will be much more significant. Do not think this is an idle concern. You're digging yourself a hole. – tadman Feb 02 '13 at 22:43

1 Answers1

0

try this

   $chatCode = mysql_real_escape_string($_GET['chat_code']) ;
   $sql = "SELECT * FROM chat WHERE chat_members_code =  '".$chatCode."' ";
echo_Me
  • 36,552
  • 5
  • 55
  • 77