1

what is wrong with this code?

$core->query("UPDATE games SET hits = hits + 1 WHERE id=".intval($id).";");

hits incerements by 2 and sometimes by 3! I mean for example hits = 3; when I call this function, hits will be 5 and sometimes 6! (add 2 and 3 instead 1).

mysql table type is MyISAM.

query function is:

function query($query) {


    $this->error="";
    $this->result=@$this->link->query($query);
    if(!$this->result) {
        $this->error=@$this->link->error;
        return FALSE;
    }

    return $this->result;
}

link is:

$link = new mysqli(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_NAME);
casperOne
  • 73,706
  • 19
  • 184
  • 253
m3hdi
  • 383
  • 1
  • 4
  • 15
  • In the past when I read those questions the explaination a) was always that the code has been executed twice, thrice, ... b) in the vast majority because the client requested the resource multiple times and c) more often than not that happend because of a browser plugin (e.g. firebug was known for request doublets under some conditions) – VolkerK Apr 25 '12 at 10:44
  • 1
    http://www.sqlfiddle.com/#!2/d2762/1 mysql code runs fine as far as I can tell. I'm with VolkerK, make sure it's not being called twice. – craniumonempty Apr 25 '12 at 10:47
  • ahh find it! it is from flash!! – m3hdi Apr 25 '12 at 10:56

3 Answers3

1

The SQL code looks correct, so it must be the context that is causing the problem.

It is possible that you put the code in an element that gets called two or three times per page? If not explicitly, through an include or subroutine structure?

D Mac
  • 3,727
  • 1
  • 25
  • 32
0

It seems that your query is correct but may be this function call for multiple time for same $id value. Please check this..

thanks

Er. Anurag Jain
  • 1,780
  • 1
  • 11
  • 19
0

It was from flash on that page.

Wouter Dorgelo
  • 11,770
  • 11
  • 62
  • 80
m3hdi
  • 383
  • 1
  • 4
  • 15