kenng Posted October 17, 2012 Share Posted October 17, 2012 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: ken@tagssg.com\n"; $mailheader .= "Reply-To: ken@tagssg.com\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 ken@tagssg.com"); ?> <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 Quote Link to comment https://forums.phpfreaks.com/topic/269594-prevent-backrefresh-submitting/ Share on other sites More sharing options...
Christian F. Posted October 17, 2012 Share Posted October 17, 2012 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). Quote Link to comment https://forums.phpfreaks.com/topic/269594-prevent-backrefresh-submitting/#findComment-1385886 Share on other sites More sharing options...
berridgeab Posted October 17, 2012 Share Posted October 17, 2012 Are you talking about a user hitting the back button and resumbiting the POST information? Quote Link to comment https://forums.phpfreaks.com/topic/269594-prevent-backrefresh-submitting/#findComment-1385887 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.