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, it is submitted to the database twice for some reason.


Solution 1:

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.