Jump to content

[SOLVED] Re-submitting forms


Ninjakreborn

Recommended Posts

I have the following form (as an example)

<?php
// this section is for the mailing list.
// first check if anything was submitted
if (isset($_POST['submit']) && $_POST['submit'] == "Subscribe") {
if ($_POST['email'] == "") { // error check email
	echo "Email Required";
	echo "<br />";
	$show = "yes";
}else { // subscribe if everything is right
	$email = mysql_real_escape_string($_POST['email']);
	$insert = "INSERT INTO mlm_users (email) VALUES ('$email');";
	if (mysql_query($insert)) {
		echo "Subscribed<br />";
	}else {
		echo "Problem subscribing please try again later.<br />";
	}
	$show = "no"; // this will stop the form from showing
}
}elseif (isset($_POST['submit']) && $_POST['submit'] == "Un-Subscribe") {
if ($_POST['email'] == "") {
	echo "Email Required";
	echo "<br />";
	$show = "yes";
}else {	
	$email = mysql_real_escape_string($_POST['email']);
	$insert = "DELETE FROM mlm_users WHERE email = '$email';";
	if (mysql_query($insert)) {
		echo "Un-Subscribed<br />";
	}else {
		echo "Problem subscribing please try again later.<br />";
	}
	$show = "no";
}
}
if ($show != "no") {
?>
<div style="float:right;"><strong><br>Sign up for the inside scoop on special     <br>promotions, contests, and exclusive     <br>bonuses for our members.</strong><br>
<form name="subscription" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<strong>Email:</strong>  <input type="email" name="email" value="" /><br /><input type="submit" name="submit" value="Subscribe" /><input type="submit" name="submit" value="Un-Subscribe" />
</form>
<font size="1"><strong>Your email address is 100% confidential and will<br>remain that way.</strong></font></div>
<?php
}
?>

Ok, in the end when someone submit's this, they can continue to resubmit it forever.  I want a simple method to do this, because I just wanted to do it above the form, very easily.

However, I don't want them to be able to re-submit the form over and over and over again and hit the system (in an attack or something).  is there a way to easily prevent form re-submittal, or hitting the refresh button over and over again, and still have roughly this same setup.

Link to comment
https://forums.phpfreaks.com/topic/47391-solved-re-submitting-forms/
Share on other sites

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.