prepare("insert into rep"/> prepare("insert into rep">

Home  >  Article  >  Backend Development  >  刷新页面总是出现这种情况怎么办?

刷新页面总是出现这种情况怎么办?

WBOY
WBOYOriginal
2016-06-06 20:17:591324browse

刷新页面总是出现这种情况怎么办?

回复是提交到本页的
form表单

<code><form method="POST">
 <input type="text" name="reid">
 <input type="text" name="name">
  <textarea id="" name="content"></textarea>
  <button type="submit">提交</button>
</form></code>



下面是插入语句
$pdo=new PDO("mysql:host=localhost;dbname=t1","root","");
$stnt=$pdo->prepare("insert into reply(reid,name,content)values(:reid,:name,:content)");
$stnt->execute($_POST);
这两个代码都是写在一个页面的 页面出现两个问题 我提交表单后这个输入框里面的东西可以插入到数据库中 然后表单就会清空 但是我点击刷新页面后总是有一个提示框 就是下面这个图片的内容 如果我点击继续后刚才已经提交的数据就会再插入一遍到数据库中 而且我换别的浏览器刷新页面也是提示这个框

回复内容:

刷新页面总是出现这种情况怎么办?

回复是提交到本页的
form表单

<code><form method="POST">
 <input type="text" name="reid">
 <input type="text" name="name">
  <textarea id="" name="content"></textarea>
  <button type="submit">提交</button>
</form></code>



下面是插入语句
$pdo=new PDO("mysql:host=localhost;dbname=t1","root","");
$stnt=$pdo->prepare("insert into reply(reid,name,content)values(:reid,:name,:content)");
$stnt->execute($_POST);
这两个代码都是写在一个页面的 页面出现两个问题 我提交表单后这个输入框里面的东西可以插入到数据库中 然后表单就会清空 但是我点击刷新页面后总是有一个提示框 就是下面这个图片的内容 如果我点击继续后刚才已经提交的数据就会再插入一遍到数据库中 而且我换别的浏览器刷新页面也是提示这个框

post 之后,最好 302 redirect 到一个新页面

设计模式PRG:Post/Redirect/Get 防止重复提交表单

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn