Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-14-2006, 06:20 PM   PM User | #1
PaulC2K
Regular Coder

 
Join Date: Jul 2005
Posts: 110
Thanks: 13
Thanked 0 Times in 0 Posts
PaulC2K is an unknown quantity at this point
Incorrect value coming through php to SQL & back

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.

PHP Code:
$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 is offline   Reply With Quote
Old 06-14-2006, 07:07 PM   PM User | #2
PaulC2K
Regular Coder

 
Join Date: Jul 2005
Posts: 110
Thanks: 13
Thanked 0 Times in 0 Posts
PaulC2K is an unknown quantity at this point
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.
PaulC2K is offline   Reply With Quote
Old 06-14-2006, 07:55 PM   PM User | #3
Kid Charming
Regular Coder

 
Join Date: Jun 2005
Posts: 804
Thanks: 0
Thanked 0 Times in 0 Posts
Kid Charming is an unknown quantity at this point
Does this script generate an image?
Kid Charming is offline   Reply With Quote
Old 06-14-2006, 08:00 PM   PM User | #4
PaulC2K
Regular Coder

 
Join Date: Jul 2005
Posts: 110
Thanks: 13
Thanked 0 Times in 0 Posts
PaulC2K is an unknown quantity at this point
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
PaulC2K is offline   Reply With Quote
Old 06-14-2006, 08:09 PM   PM User | #5
Kid Charming
Regular Coder

 
Join Date: Jun 2005
Posts: 804
Thanks: 0
Thanked 0 Times in 0 Posts
Kid Charming is an unknown quantity at this point
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.
Kid Charming is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:42 AM.


Advertisement
Log in to turn off these ads.