0

I am trying to get this counter working but for some reason i get an error.

"mysql_result() expects parameter 1 to be resource, boolean given in *\functions\users.php on line 85"

I have an if statement that checks if the user is logged in:

if(logged_in() === true){
    $session_user_id = $_SESSION['user_id'];
    $user_data = user_data($session_user_id, 'user_id', 'username', 'password');        
}

and a function that will update the data base:

function online_user_count(){
    mysql_query("UPDATE `users` SET LastTimeSeen = NOW() WHERE `user_id` = " . $_SESSION['user_id']); 
    return mysql_result(mysql_query("SELECT COUNT(*) FROM `users` WHERE LastTimeSeen > DATE_SUB(NOW(), INTERVAL 5 MINUTE)"), 0);
}

which i then call on my main home page:

 <?php echo online_user_count(); ?>

what is wrong?

scrowler
  • 24,273
  • 9
  • 60
  • 92
  • It means that your `mysql_query` call is failing (returning boolean false) - these functions are well deprecated... Changing them to `mysqli` or `PDO` won't help your problem but will help you get more support for it – scrowler Jan 30 '14 at 03:54
  • i would like to suggest you to use the singleton / static class for this purpose.. on login increment the variable and on logout decrease it by one. or u can also try with application level variable.. – Deepak Sharma Jan 30 '14 at 04:30
  • possible duplicate of [mysql\_fetch\_array() expects parameter 1 to be resource, boolean given in select](http://stackoverflow.com/questions/2973202/mysql-fetch-array-expects-parameter-1-to-be-resource-boolean-given-in-select) – John Conde Jan 30 '14 at 12:49

1 Answers1

0

Maybe there is an error in the query into the mysql_result. Could you test this query into the phpmyadmin or in a mysql console? and if it has an error you can see it there.