-2

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

I'm using this code to pull out the status of an applicant in the database so their status appears when they login, based on the user ID but I am getting the follwing errors:

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in 
Warning: mysql_free_result() expects parameter 1 to be resource, boolean given in 

$result = mysql_query("SELECT status from users where user_id = ".intval($_SESSION['user_id']));

while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
    printf("status: %s  ", $row[0]);
}

mysql_free_result($result);
echo $row['status'];

Thanks in advance

Community
  • 1
  • 1
user1257518
  • 153
  • 6
  • 17
  • 1
    You don't typically need to call `mysql_free_result`. From the manual: "`mysql_free_result()` only needs to be called if you are concerned about how much memory is being used for queries that return large result sets. All associated result memory is automatically freed at the end of the script's execution." See also http://stackoverflow.com/questions/2502201/is-it-a-good-practice-to-use-mysql-free-resultresult – Mark Byers Apr 18 '12 at 12:58

2 Answers2

1

You are getting this message because your query is failing for some reason. Add or die(mysql_error()) after your query to see the error.

This should be used for debugging purposes and should be handled more gracefully when you move your application to production.

Travesty3
  • 14,608
  • 6
  • 56
  • 96
0

This should be like this

$result = mysql_query("SELECT status from users where user_id = '".intval($_SESSION['user_id'])."'");

You were missing single quotes

Muhammad Raheel
  • 19,645
  • 7
  • 66
  • 101