0

I get error while running this code in my home page Im trying to get number of registered accounts on my website

code:

function user_count(){
    $query = mysqli_query($GLOBALS["con"], 'SELECT COUNT user_id FROM users WHERE active = 1');
    $row = mysqli_fetch_assoc($query);
    return $row;
}

$GLOBALS["con"] is defined in another place as 
$GLOBALS["con"] = mysqli_connect("localhost","root","","Login"); 

I get this error on my page:

Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, boolean given in /Applications/XAMPP/xamppfiles/htdocs/core/functions/users.php on line 4

Any ideas on this? I would like to resolve this problem...

Pupil
  • 23,834
  • 6
  • 44
  • 66
Oskar Martin
  • 73
  • 2
  • 12
  • Please try to use the select query like that way : SELECT COUNT(user_id) FROM users WHERE active = 1 – Lakhan Jan 05 '15 at 13:22
  • Thanks for the answer ! I found the solution by myself eventually. Used mysqli_num_row instead of mysqli_fetch_assoc and that resolved the problem. Also had to remove COUNT from query line. – Oskar Martin Jan 05 '15 at 13:34

0 Answers0