Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Jul 2005
    Posts
    131
    Thanks
    21
    Thanked 0 Times in 0 Posts

    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!

  • #2
    Regular Coder
    Join Date
    Jul 2005
    Posts
    131
    Thanks
    21
    Thanked 0 Times in 0 Posts
    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.

  • #3
    Regular Coder
    Join Date
    Jun 2005
    Posts
    804
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Does this script generate an image?

  • #4
    Regular Coder
    Join Date
    Jul 2005
    Posts
    131
    Thanks
    21
    Thanked 0 Times in 0 Posts
    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

  • #5
    Regular Coder
    Join Date
    Jun 2005
    Posts
    804
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •