I am looking for a way to stop inserting or sending data in the database when refreshing the page.
here is my code:
user_details_page.php
<
We can stop it without redirect , best way to use PHP $_SESSION like this :
if($_SERVER['REQUEST_METHOD'] == 'POST' && empty($_SESSION['form_submit']) )
{
extract($_POST);
$sql=""INSERT INTO table (username, useremail, email) VALUES('$username','$useremail','$email')";
$_SESSION['form_submit']='true';
}
else
{
$_SESSION['form_submit']='NULL';
}
Once an insert or update is done in your code you always need to redirect to another page.
See here on how to do that: How to make a redirect in PHP?
(You want to use a PHP redirect, not a Javascript or HTML one, because you obviously really need this to work.)
The confirm page should be what you redirect to after the update, not what does the insert.
The fast way is to redirect the page to it's current location:
if (isset($_POST['submit']))
{
//do somthing
header("Location: $current_url");
}
The best way to prevent that is to add header('Location: filename') after your query. Thus in your case,
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');
//must be inside the condition to prevent too many redirects
header('Location: user_details_page.php');
}