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");
exit;
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');
exit;
Stop Inserting Blank data in Refreshing browser
Just verify if the $_POST
is not empty
if(!empty($_POST))
{
$sql="INSERT INTO te(Dat,Sadi,Jam,Washi) VALUES('$_POST[Dat]','$_POST[Sadi]','$_POST[Jam]','$_POST[Washi]')";
if (!mysql_query($sql, $sub))
{
die('Error:'.mysql_error());
}
}
How to prevent form resubmission when page is refreshed (F5 / CTRL+R)
Use the Post/Redirect/Get pattern. http://en.wikipedia.org/wiki/Post/Redirect/Get
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
How to Capitalize First Letter in Laravel Blade
Disable the Button in the Table Based on the Td Text
In Laravel How to Get Data in One Query from 3 Tables
How to Count Occurrence of Duplicate Items in Array
Laravel Drop Down Multiple Values from Db in Drop Down
How Would I Skip Optional Arguments in a Function Call
How to Insert Special Character in MySQL Via PHP and Display on HTML Page
How to Prevent SQL Injection in PHP
SQL Injection That Gets Around mysql_real_escape_string()
404 Not Found; Apache Server Can't Load Simple PHP File
Generating a Truly Unique Order Id in PHP
Codeigniter - Call to a Member Function Result() on Boolean In
Php Session Lost After Redirect
Getting Date Format M-D-Y H:I:S.U from Milliseconds