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
<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');
}
so the problem everytime I refresh the confirm page.php the data is sent to the database. how to stop this?
i have this solution by using session
We can stop it without redirect , best way to use PHP $_SESSION like this :
confirm_page.php:
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 best way to prevent that is to add header('Location: filename') after your query. Thus in your case,