I have a small hit counter script on my site, but its not giving the correct results on this one site for some reason.
$result = mysql_query("SELECT * FROM `webstats` WHERE filename = '$filename' AND folder = '$folder' ",$db);
if ($myrow = mysql_fetch_array($result))
$hitcounter = $myrow['hitcounter'];
$id = $myrow['id'];
$sql = "UPDATE webstats SET
folder = '$folder', filename = '$filename', hitcounter='$hitcounter', ip='$ip', date='$date', time='$time' WHERE id = '$id' ";
$result = mysql_query($sql) or die ("Could not successfully run query ($sql) because: " . mysql_error());
The time, date & file values are already generated, but thats the only part of the code which looks at this specific table, and makes any changes to it.
When the page refreshes or loads up, it finds the specific entry in the db, gets it, adds one, and uploads it back in there with info as to the last visit there etc.
The only problem is that its adding 2!!??
I have only 1 page which connects to this code, and on that page i have the results of all the page hits.
When i look at the page, its always an odd number, it'll be say 11, then i'll refresh and it says the value is 13.
If i look in the database at this point, it says the value is 14!?
This exact script works fine on other sites, but im not 100% sure if its ever worked on sites located on this server as this is the first time i've come to include this code on the sites since i moved onto this server about 5 weeks ago.
Has anyone seen something like this before and have any idea what could be causing this? I know its not the script or the page, so i can only think something else is causing this problem. The variable name is unique, so its not getting confused with something else, but its happily doubling up my supposed page hit counts!