...

View Full Version : Incorrect value coming through php to SQL & back



PaulC2K
06-14-2006, 06:20 PM
Hi,

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'];
$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!

PaulC2K
06-14-2006, 07:07 PM
Hmmm, it seems this isnt the only very weird thing its doing!
When i log in, its uploading the information twice too.

PaulC2K 14/06/2006 18:02.28 xxx.xxx.xxx.xxx
PaulC2K 14/06/2006 18:02.27 xxx.xxx.xxx.xxx
PaulC2K 13/06/2006 16:08.37 xxx.xxx.xxx.xxx
PaulC2K 13/06/2006 16:08.36 xxx.xxx.xxx.xxx

The actions definately dont match the code, something else is happening to cause this.

Kid Charming
06-14-2006, 07:55 PM
Does this script generate an image?

PaulC2K
06-14-2006, 08:00 PM
Image? No, just logs when that script is loaded, takes the name of the folder and file your looking at, and puts it into a database.... twice :confused:

Kid Charming
06-14-2006, 08:09 PM
It looks like something is causing your script to be called twice. I asked about the image because I've run into this before with scripts that generated images without an expires header. From what I've seen, though, I'm not sure what would be causing it.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum