Soley
Soley

Reputation: 1776

updating my table with prepare command increase the value by 2

I am trying to run this simple mysqli command in php:

$query = "UPDATE config SET visit = visit + 1";
if ($stmt = $con->prepare($query)) {
    $stmt->execute();
    $stmt->close();
}

Table config only has 1 row. However, the value instead of 1, it is increasing by 2!

So if the current value is 0, the next value will be 2, and then 4, etc!

I cannot understand this.

Upvotes: 3

Views: 39

Answers (1)

Your Common Sense
Your Common Sense

Reputation: 157896

The problem has nothing to do with prepared statements (by the way, you don't need one here) nor even with sql at all. It is your whole php script being executed twice, thanks to wrong implementation of SEO friendly urls. You have to always verify if you're processing a valid request. And never run any SQL for invalid ones.

PS. Add favicon.ico for your site.

I'll take a liberty to stress on it again. It is not favicon.ico to blame, but wrong implementation of SEO friendly urls. There will be hundreds other requests that should result in 404 response, not views increment. You have to cure the disease, not one of symptoms. You have to fix your entry point that should not process requests to image files at whole.

Upvotes: 2

Related Questions