Reputation: 327
I have a page that contains a few forms, I need to be able to prevent a user from submitting a duplicate of each particular form by logging their ip address when they submit it.
If an existing entry is found in the mysql database, from that ip address for the form that they submitted, but the input submitted is different, I need to be able to update that entry with the new value.
If the input is the same, I need it to be discarded.
<form action="" name="form1" method="post">
<input type="text" value="" name="A" />
<input type="text" value="" name="B" />
<input type="text" value="" name="C" />
<input type="text" value="" name="D" />
<input type="Submit" value="Submit Form" name="submitForm" />
</form>
<form action="" name="form2" method="post">
<input type="text" value="" name="A" />
<input type="text" value="" name="B" />
<input type="text" value="" name="C" />
<input type="text" value="" name="D" />
<input type="Submit" value="Submit Form" name="submitForm" />
</form>
<form action="" name="form3" method="post">
<input type="text" value="" name="A" />
<input type="text" value="" name="B" />
<input type="text" value="" name="C" />
<input type="text" value="" name="D" />
<input type="Submit" value="Submit Form" name="submitForm" />
</form>
Upvotes: 0
Views: 71
Reputation: 199
I can provide you a proper work around for your requirement,
$ip = $_SERVER["REMOTE_ADDR"]; //store the visitors ip to a variable
$retval = mysql_query("SELECT * FROM table WHERE ip ='$ip' ");
if( mysql_num_rows($retval) > 0) {
mysql_query("UPDATE table SET val1 = '$form_val' "); //If Ip exist, update
}
else
{
mysql_query("INSERT INTO table (val1) VALUES ('$form_val') ");//else insert
}
Upvotes: 1