-2

I have the following code:

<?
include"mysql.php";
$getusers= mysqli_query ("select count(*) as cnt from users",$c);
$totalusers= mysqli_fetch_array ($getusers);
$totalusers=$totalusers['cnt'];
$getusers= mysqli_query ("select * from users",$c);
$totalmoney=0;
while($usr= mysqli_fetch_array ($getusers))
{
$totalmoney=$totalmoney+$usr['total_earned'];
}
$getoffers= mysqli_query ("select count(*) as cnt from offers where         active=1",$c);
$ocnt= mysqli_fetch_array ($getoffers);
$ocnt=$ocnt['cnt'];

print"<p>Total Offers: $ocnt<br>Total Members: $totalusers<br>Total Earned:   \$$totalmoney</p>";

?>

still it gives me this error:

Warning: mysqli_query() expects parameter 1 to be mysqli, string given in /home/u705139137/public_html/header.php on line 48

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in /home/u705139137/public_html/header.php on line 49

Warning: mysqli_query() expects parameter 1 to be mysqli, string given in /home/u705139137/public_html/header.php on line 51

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in /home/u705139137/public_html/header.php on line 53

Warning: mysqli_query() expects parameter 1 to be mysqli, string given in /home/u705139137/public_html/header.php on line 57

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in /home/u705139137/public_html/header.php on line 58

What have I done wrong?

Community
  • 1
  • 1
  • 1
    Actually reading the error message would be a start. Then reading the manual the second step. – deceze Aug 21 '15 at 09:18

2 Answers2

0

Change your mysqli_query like below

 <?
    include"mysql.php";
    $getusers= mysqli_query ($c,"select count(*) as cnt from users");
    $totalusers= mysqli_fetch_array ($getusers);
    $totalusers=$totalusers['cnt'];
    $getusers= mysqli_query ("select * from users",$c);
    $totalmoney=0;
    while($usr= mysqli_fetch_array ($getusers))
    {
    $totalmoney=$totalmoney+$usr['total_earned'];
    }
    $getoffers= mysqli_query ("select count(*) as cnt from offers where         active=1",$c);
    $ocnt= mysqli_fetch_array ($getoffers);
    $ocnt=$ocnt['cnt'];

    print"<p>Total Offers: $ocnt<br>Total Members: $totalusers<br>Total Earned:   \$$totalmoney</p>";

    ?>

Look ; http://www.w3schools.com/php/func_mysqli_query.asp

Muhammet Arslan
  • 975
  • 1
  • 9
  • 33
0

Do it like that

$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
$getusers= mysqli_query ($mysqli, "select count(*) as cnt from users");

http://php.net/manual/en/mysqli.query.php

fab
  • 1,189
  • 12
  • 21