开发者

Insert query on page load, inserts twice?

On my games page, I have a page where they play a game. On that page I have a query

$insert_user_activity = mysql_query("INSERT INTO game_activity (user_id,user_full_name,game_id,game_name) values ('$user_id','$full_name','$browser_id','$game_title')");

Which will log it into my database, it's just sitting on its own and when I refresh the page, 开发者_JS百科it is submitted to the database twice for some reason.


The logic of your front controller is wrong.

The page where you are executing this query is called on every request made to your site, no matter whether it's a proper request or a call to a non-existent resource.

You must change the logic of the front controller so it wouldn't run the application for the invalid requests. Otherwise there will be not one but thousands false inserts when the site goes live.


what's the conditions on the page for which the query execute or in other way how are values of the variable you are getting on the page to execute the query if it is so than first check the existence of variables if the variables are set than run the query.


I was having problems with a query that was executed twice in Firefox but in other bowsers (Chrome and IE) did problem did not happen. I was searching for an answer and found this post.

I discovered this:

If i execute a simple insert query it gets inserted twice when i switch on the "net" functionality in Firebug this does not happen. Strange. Just wanted to add this to this post. Still trying to solve this.

{edit} Update: I have found a solutions, although it is not a pretty one. I check first wicth an select count if such record exists, if not then it will be inserted otherwise it will not be. Did the trick for me.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜