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.

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

报告相同问题?

悬赏问题

  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路