You can redirect the page after inserting data using:
header('Location:'.$_SERVER['PHP_SELF']);
After the redirect, the whole page will be reloaded, and updating will not cause the data to be reinserted.
if(isset($_POST['contactus'])) { $honeypot = $_POST['email_confirm']; $name = $_POST['name']; $email = $_POST['email']; $comments = $_POST['comments']; // honeypot if($honeypot) exit(1); //error messages if(trim($name) == '') { $error = '<div class="error_message">Need your name</div>'; } else if(trim($email) == '') { $error = '<div class="error_message">Need your email</div>'; } else if(!isEmail($email)) { $error = '<div class="error_message">Need a valid email</div>'; } else if(trim($comments) == '') { $error = '<div class="error_message">A message is required</div>'; } if($error == '') { if(get_magic_quotes_gpc()) { $comments = stripslashes($comments); } //email address $address = " email@example.com "; //email message $e_subject = 'Web Message from: ' . $name . '.'; $e_body = "From: $name\nEmail: $email \r\n\nMessage:\n$comments\n\n\n"; $msg = $e_body . $e_content . $e_reply; if(mail($address, $e_subject, $msg, "From: $email\r\nReply-To: $email\r\nReturn-Path: $email\r\n")) { //success html page response echo "<div id='succsess_page'>"; echo "<h1>Email Sent Successfully.</h1>"; echo "<p>Thank you <strong>$name</strong> , your message has been submitted. </p>"; echo "</div>"; } else echo "Error. Mail not sent"; } header('Location:'.$_SERVER['PHP_SELF']); }
Jenz
source share