刷新PHP时双重提交 [英] double submission when refresh php

查看:75
本文介绍了刷新PHP时双重提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试纠正脚本中两次提交的问题.当我按提交时,它只更新一次mysql(这就是我想要的).但是,当我点击刷新时,它将再次更新mysql.按下刷新按钮后,似乎会忽略if语句.我该怎么做才能阻止

I'm trying to correct the issue of double submit in my script. When I press submit it only updates mysql once(which is what I want). However, when I hit refresh it updates mysql again. It seems to ignore the if statement once the refresh button is hit. What would I do to stop this

这是我的代码

if (isset($_POST['submitButton'])) { 
//do something
 }


<form action = "table.php" method="post">
<label for="submitButton"></label>
<input type="submit" name="submitButton" id="submitButton"
value="Submit Form"/>
</form>

推荐答案

刷新页面时-再次发送帖子

某些浏览器实际上会警告您发生这种情况.

Some browsers actually warn you about that happening.

为防止我这样做:

if (isset($_POST['submitButton'])) { 
//do something

//..do all post stuff
header('Location: thisPage.php'); //clears POST
}


<form action = "table.php" method="post">
<label for="submitButton"></label>
<input type="submit" name="submitButton" id="submitButton"
value="Submit Form"/>
</form>

这篇关于刷新PHP时双重提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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