Reputation: 123
i have this simple update query :
update `table_name` set `count` = `count` + 1 where `id` = '$id'
But every time i reload the page the count is incremented by 2 in the db. What is going on here? Thanks..
Upvotes: 1
Views: 92
Reputation: 231
Try Below Code : Fetch count first from that table and increment it and then update the table
$count = SELECT count(*) FROM `table_name`
$count1 = $count + 1;
update `table_name` set `count` = '$count1' where `id` = '$id'
Upvotes: 1
Reputation: 1
Try declaring a variable before you call it in the query like this : Also im not sure if your 'count' is a string or also a variable.
$count2 = 'count' + 1;
update `table_name` set `count` = '$count2' where `id` = '$id'
Upvotes: 0
Reputation: 15454
It's a browser issue. Your browser visit page twice.
Why it could be:
img
or script
without or empty src
attr. {background-image: url();}
Explore your browser console for requests.
Upvotes: 2