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信息。如果您需要存储错误消息之类的内容,请使用会话。

更多相关文章

  1. php如何跨站抓取别的站点的页面的补充
  2. wordpress永久链接重新加载页面,而不是重定向到发布
  3. 在返回按钮上重新加载页面。
  4. ajax在php页面上获得一个值的结果
  5. php使用DOMDocument更改div但不更新页面
  6. 通过添加3hrs从服务器中重新获取CURTIME()并在PHP页面中显示它
  7. 使用jQuery或Javascript重定向到具有值的给定页面
  8. 来自加载页面的Javascript响应未显示在中,尽管我可以在firebug中
  9. 添加到数据库后,保持在同一页面而不刷新它

随机推荐

  1. Activity的启动流程
  2. Android 音量增加减少按钮事件
  3. android调用系统的相机服务
  4. AIDL
  5. android--------Android Studio常见问题
  6. wav格式
  7. Android Studio 修改api level
  8. android基础:动画案例(图片翻转)
  9. Android面试-基础知识
  10. javascript获取Android设备版本信息(备忘)