如何在刷新页面时停止“Conform form resubmission”对话框
I am using an subscribe script to add the user email address to mysql record. I used the below code for this process .It works fine .after user submit the email the page is refreshed and database is also updated to mysql :-) . But the issue is ,When i refresh the page after submitting the email ,i'm getting an conform form resubmission dialog .If i click continue button the same email (dublicate) is updating in new record.my db is updating with same email address when the i refresh page. How to disable this message and stop updating the same duplicate records in mysql.
我使用订阅脚本将用户电子邮件地址添加到mysql记录。我使用下面的代码进行此过程。工作正常。用户提交电子邮件后页面刷新,数据库也更新为mysql :-)。但问题是,当我在提交电子邮件后刷新页面时,我正在获得一致的表单重新提交对话框。如果我点击继续按钮,同一个电子邮件(dublicate)正在更新新记录。我的数据库正在使用相同的电子邮件地址进行更新当我刷新页面。如何禁用此消息并停止更新mysql中的相同重复记录。
<form id="myForm" action="" onsubmit="return validateForm();"method="post">
<input type="hidden" name="action" value="update" />
<input type="text" name="email" id="email" value="Enter your email here" onfocus="if (this.value == 'Enter your email here') {this.value = '';}" onblur="if (this.value == '') {this.value = 'Enter your email here';}" onwebkitspeechchange = "this.value = this.value.replace('Enter your email here','')" style=" margin:0px 0px 0px 26px;color:#999; border:4px solid #bbb;border-radius:6px;font-size:1em;width:260px;height:30px; font-style:italic; font-family:"Times New Roman", Times, serif;"/>
<br>
<center>
<input class="button" type="image" src="rss.png" />
</center>
</form>
<?php
$email = $_POST['email'];
mysql_connect ("localhost", "root", "") or die ('Error: ' . mysql_error());
mysql_select_db ("test");
$query="INSERT INTO newsletter_emails (email)VALUES ('".$email."')";
mysql_query($query) or die ('Error updating database');
?>
<script>
function validateForm() {
var x = document.forms["myForm"]["email"].value;
var atpos = x.indexOf("@");
var dotpos = x.lastIndexOf(".");
if (atpos < 1 || dotpos < atpos + 2 || dotpos + 2 >= x.length) {
alert("Not a valid e-mail address");
return false;
} else {
alert("thankyou");
}
}
</script>
2 个解决方案
#1
6
When you submit a form, do a standard redirect afterwards. That way no POST info will be sent with the redirect. If you need to store things like an error message, use sessions.
提交表单后,请执行标准重定向。这样,重定向就不会发送POST信息。如果您需要存储错误消息之类的内容,请使用会话。
更多相关文章
- php如何跨站抓取别的站点的页面的补充
- wordpress永久链接重新加载页面,而不是重定向到发布
- 在返回按钮上重新加载页面。
- ajax在php页面上获得一个值的结果
- php使用DOMDocument更改div但不更新页面
- 通过添加3hrs从服务器中重新获取CURTIME()并在PHP页面中显示它
- 使用jQuery或Javascript重定向到具有值的给定页面
- 来自加载页面的Javascript响应未显示在中,尽管我可以在firebug中
- 添加到数据库后,保持在同一页面而不刷新它