douyu53265 2015-06-13 18:15
浏览 27
已采纳

MySQLi查询在每次浏览器刷新时运行

When I run this code, the "INSERT INTO aks_balance_history" query and "UPDATE aks_account" query runs again and again.Also database is getting updated on each refresh, while the "UPDATE aks_counter" runs only once (as required). I am really stuck in this code please help.

if(isset($_POST['update_btn_counter']))
        {
            mysqli_query($link,"INSERT INTO aks_balance_history(bh_amount,bh_from,bh_to,bh_reason) VALUES('".$_POST["used_balance"]."','Counter Cash','".$_POST["select_account"]."','".$_POST["reason"]."') ");
            mysqli_query($link,"UPDATE aks_counter SET counter_balance = counter_balance - '$_POST[used_balance]' WHERE counter_id='0' ");
            mysqli_query($link,"UPDATE aks_account SET account_balance = account_balance + '$_POST[used_balance]' WHERE account_title='$_POST[select_account]' ");
        }
  • 写回答

1条回答 默认 最新

  • dongxu7121 2015-06-13 19:15
    关注

    Sure, that is because the browser sends the same request again. That is what you asked it to to when refreshing. If you want to prevent that, then you have to redirect the browser after having performed the database operations. You typically redirect it to some read only code that reads the result from the database and displays it. Then you can refresh how often you want.

    Currently you do not reload the form, but the result of the form you got after the first submit. To re-deliver that result the server must re-run the same code, thus the same operations are performed.

    A typical solution is to send a forms submission to some processing script and the redirect back to the form if that should be offered again.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 flink cdc无法实时同步mysql数据
  • ¥100 有人会搭建GPT-J-6B框架吗?有偿
  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名