I have fields added to database by user. After pressing the submit button, I redirect the page to another place, but if the user clicks back from the web browser, the same form comes and if he clicks the submit button again, the fields are added to the database. How can I prevent this?
Following my code:
HTML
<form action="index.php" method="post">
<input type="text" name="firstname">
<input type="text" name="lastname">
<button name="submitForm">Submit</button>
</form>
PHP
if (isset($_POST['submitForm'])) {
$insert = $connect->prepare("INSERT INTO users (firstname,lastname) VALUES ('{$_POST['firstname']}','{$_POST['lastname']}')");
$insert->execute();
if($insert){
header('Location:index.php?Status=True');
}else {
header('Location:index.php?Status=False');
}
}