Stop Inserting Data in the Database When Refreshing the Page

stop inserting data in the database when refreshing the page

Header the user to a new page :

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");

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!

How to stop insert into after refreshing a page

After the data has been inserted to the database, redirect and exit.

header('location: thepage.php');

Stop Inserting Blank data in Refreshing browser

Just verify if the $_POST is not empty

$sql="INSERT INTO te(Dat,Sadi,Jam,Washi) VALUES('$_POST[Dat]','$_POST[Sadi]','$_POST[Jam]','$_POST[Washi]')";
if (!mysql_query($sql, $sub))

How to prevent form resubmission when page is refreshed (F5 / CTRL+R)

Use the Post/Redirect/Get pattern.

With my website, I will store a message in a cookie or session, redirect after the post, read the cookie/session, and then clear the value of that session or cookie variable.

Related Topics

Leave a reply