php counter, why not working?

Joined
12 Feb 2006
Posts
17,637
Location
Surrey
ok well im stuck trying to add a php counter which i have used times before, but now its not working so come here for some help.

this is the code im using

Code:
<? include ("stats/db.php");
$date = date("M d, Y"); 
$hitadd= MYSQL_QUERY("INSERT INTO stats(date, ip)".
"VALUES ('$date', '$REMOTE_ADDR')"); ?>

and to display it
Code:
<?
include ("stats/db.php");
$date = date("M d, Y");
$uniquea = mysql_query("SELECT DISTINCT ip FROM stats");
$uniqueb = mysql_num_rows($uniquea);
$tdayua = mysql_query("SELECT DISTINCT ip FROM stats WHERE date = '$date'");
$tdayub = mysql_num_rows($tdayua);
$hitsa = mysql_query("SELECT * from stats");
$hitsb = mysql_num_rows($hitsa);
$tdayhitsa = mysql_query("SELECT * from stats where date = '$date'");
$tdayhitsb = mysql_num_rows($tdayhitsa);
echo ("Total Hits: $hitsb <br />
Total Unique Hits: $uniqueb<br />
Hits Today: $tdayhitsb<br />
Unique Hits Today: $tdayub
");
?>

this is just a straight copy from another site i made which it works completely fine for, well atleast the total hits and hits today works, but using it on new site i just get total hits but its actually displaying the total amount of unique hits.

So am i doing something wrong?
 
First clean the code (short tags, register globals, echo and include are constructs not requiring function syntax etc.). Then do some debugging: have you checked the database in PHPMyAdmin? If it's populated, have you echoed or used print_r() on the variables to see their contents and structure? If it's not, check your database connection etc. etc.

Also I'd use a MySQL or Unix timestamp instead of a pre-formatted date, much more flexible.
 
Back
Top Bottom