我有一个包含几个表单的页面,我需要能够阻止用户提交每个特定表单的副本,方法是在提交时记录他们的ip地址。
如果在mysql数据库中找到了一个现有条目,来自他们提交的表单的ip地址,但是所提交的输入是不同的,我需要能够用新的值更新该条目。
如果输入是相同的,我需要它被丢弃。
<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>发布于 2015-03-09 09:40:54
我可以为你的要求提供一个合适的工作,
$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
}https://stackoverflow.com/questions/28938689
复制相似问题