刷新页面时停止在数据库中插入数据 [英] stop inserting data in the database when refreshing the page

查看:86
本文介绍了刷新页面时停止在数据库中插入数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种刷新页面时停止在数据库中插入或发送数据的方法.

I am looking for a way to stop inserting or sending data in the database when refreshing the page.

这是我的代码:

user_details_page.php

user_details_page.php

<form action="confirm_page.php" method="post" >
User Name:  
<input  type="text" name="username" >
User Email
<input  type="text" name="useremail" >
Password:  
<input  type="text" name="password" >
<input type="submit"  name="submit" >
</form>


confirm_page.php


confirm_page.php

if (isset($_POST['submit'])) 
{
$user= $_POST['username'];
$email = $_POST['useremail'];
$pass= $_POST['password']; 

mysql_query("INSERT INTO table (username, useremail, email) VALUES ('$username','$useremail','$email');

}

所以每次我刷新确认页面时都会出现问题.php数据被发送到数据库.如何停止呢?

so the problem everytime I refresh the confirm page.php the data is sent to the database. how to stop this?

推荐答案

将用户引导到新页面:

if (isset($_POST['submit'])) 
{
  $user= $_POST['username'];
  $email = $_POST['useremail'];
  $pass= $_POST['password']; 

  mysql_query("INSERT INTO table (username, useremail, email) VALUES(`$username','$useremail','$email')");

}
//best outside the if statement so user isn't stuck on a white blank page.
header("location: landing_page.php");
exit;

这样做,刷新的用户将刷新landing_page.php,这意味着它不会重复执行两次插入操作.

By doing this the user who refreshes will be refreshing landing_page.php which means it won't do the insert twice.

最佳建议:如果不插入,请检查用户是否首先存在!

best advice: do a check to see if user exists first if so don't insert!

这篇关于刷新页面时停止在数据库中插入数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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