用PHP更新MySQL字段的问题 [英] Problem with updating a MySQL field with PHP

查看:72
本文介绍了用PHP更新MySQL字段的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个查询:

更新选项SET投票=投票+ 1 WHERE choice_id ='$ user_choice'

UPDATE choices SET votes = votes + 1 WHERE choice_id = '$user_choice'

但是,当我在脚本中执行该命令时,votes字段将更新两次,因此投票将从4变为6而不是5.似乎没有被调用两次,因为我回显了要测试的内容这样,只会得到一个回声.有没有一种方法可以使PHP每个页面刷新"仅执行一次此查询?

But when I execute it in my script, the votes field is updated twice, so the votes will go from 4 to 6 instead to 5. It doesn't seem that it is getting called twice because I echo out stuff to test this and only get one echo. Is there a way to have it so PHP will only execute this query once per page "refresh"?

编辑:感谢您的答复,我使用的是常规MySQL,没有MySQLi或PDO.我发现的另一件事是,在执行查询时,当您从0开始并更新为1时,它可以工作,但是之后它变为3、5、7,...

EDIT: Thanks for the responses, I'm using regular MySQL, no MySQLi or PDO. Another thing I found is that when doing the query, it works when you start out with 0 and update to 1, but then after that it goes 3, 5, 7, ...

推荐答案

另一个选择是,如果您完全使用firefox并安装了bugbug,则需要禁用缓存.由于某种原因,firbug导致对dB的两次调用.花了几周的时间弄清了我作为质量检查人员的工作方式,以便在测试时获得各种奇怪的结果.他是唯一一个拥有萤火虫的人.

One other option is, if you are using firefox at all and have firbug installed you need to disable your cache. For some reason firbug results in two calls to the dB. Took weeks to figure this out where I work as QA was getting all kinds of strange results when testing. he was the only one with firebug.

这篇关于用PHP更新MySQL字段的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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