我正在寻找一种刷新页面时停止在数据库中插入或发送数据的方法。
这是我的代码:
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
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'); }
因此,每次我刷新确认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')"); } //best outside the if statement so user isn't stuck on a white blank page. header("location: landing_page.php"); exit;
通过这样做,刷新的用户将得到刷新landing_page.php,这意味着它将不会重复执行两次插入操作。
landing_page.php
最好的建议 :如果没有,请检查用户是否首先存在!