在页面加载时插入查询,是否插入两次? [英] Insert query on page load, inserts twice?

查看:88
本文介绍了在页面加载时插入查询,是否插入两次?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的游戏页面上,我有一个页面供他们玩游戏.在该页面上,我有一个查询

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.

我对php很陌生,所以如果有人可以给我一些不错的反馈而又不给我滥用的话.那会很令人惊讶的.

I am quite new to php so if anyone could give some nice feedback without giving me abuse. That would be much apreciated.

推荐答案

前端控制器的逻辑错误.

无论对站点是正确的请求还是对不存在的资源的调用,都会在对站点的每个请求上调用执行该查询的页面.

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.

这篇关于在页面加载时插入查询,是否插入两次?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆