Jump to content

Prevent Back/refresh Submitting


kenng

Recommended Posts

Hi guys, How do i prevent it from resubmitting? When ever, i go back and submit again. It will have multiple echo out different names.

 

Heres my php.

 

<?php
include("connect.php");
  if(isset($_GET['process']))
  {
$emailCheck = mysql_query("SELECT email, mobile FROM user_info WHERE email = '$_POST[email]' OR mobile = '$_POST[mobile]'") or die (mysql_error());
$number = mysql_num_rows($emailCheck);
if ($number > 0) {
echo "You already registered.";
}
else {
$query = "Insert INTO user_info (lastname, firstname, email, mobile, gender) values('$_POST[lastname]', '$_POST[firstname]','$_POST[email]','$_POST[mobile]', '$_POST[gender]')";
   $result = mysql_query($query) or die(mysql_error());
   if(!$result)
   {
 echo "Opps something went wrong. Please try again. ERROR: ".mysql_error();
   }
   else
   {
$name = $_POST['firstname'];
$query = "select * from user_info where firstname = '$name'";
$result = mysql_query($query);
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
$email = $_POST[email];
$EmailSubject = "You've Just Registered On Health Board";
$mailheader = "From: [email protected]\n";
$mailheader .= "Reply-To: [email protected]\n";
$mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n";
$MESSAGE_BODY .= "Dear " . $line['lastname'] . " " . $line['firstname'] .  ",</h1>" . "<br /><br />Thank you for registering with us, I hope you have a good day.<br /><br />Regards,<br /><br />Health Board";
mail($email, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Encounter some error. Please contact [email protected]");
?>
<html>
<head>
<title>Submitted</title>
<meta http-equiv="refresh" content="5;url=index.html" />
<meta HTTP-EQUIV="Pragma" content="no-cache">
<meta HTTP-EQUIV="Expires" content="-1">
<link href="style.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id="wrapper">
 <h1>Thank you,
   <?
echo $line['lastname'] ;
echo " ";
echo $line['firstname'] ;
?>
 </h1>
 Thank you for submitting.
 <p>In addition, a confirmation copy was sent to your e-mail address.</p>
 <p>You will be back in 5secs</p>
</div>
</body>
</html>
<?
}
}
   }
   }
mysql_close($db);
?>

 

Please excuse my coding... still new. Thanks

Link to comment
https://forums.phpfreaks.com/topic/269594-prevent-backrefresh-submitting/
Share on other sites

If you take a look at my rewrite of a login form, and pay attention to how I've structured it up (compared to the original), you should see how to do this quite nicely. The header call at the end, that sends the user to the confirmation page, prevents the F5 == resubmit problem.

My use of functions to perform most of the code also allows you to have much better control over which code paths gets executed, and how you can mix and match different functionality to get the desired results (without jumping through too many hoops).

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.