Home > php教程 > php手册 > body text

怎么防止刷新网页重复插入数据

WBOY
Release: 2016-05-25 16:53:27
Original
1652 people have browsed it

关于怎么防止刷新网页重复插入数据方法很多也很简单的,下面我们就来提供几种参考的处理方法吧。

如何防止刷新网页插入数据:

我做了一个留言板,但是每次刷新就会插入信息,请问怎么做才能防止刷新插入数据呢

JS每次操作后返回

<?php
$regs=mysql_query($shouruinsert,$conn); 
    if($regs) echo "<script>window.alert(\"操作成功\");</script><font size=3><a href=inout.htm>你的收入已经入库,请返回.不要刷新本页以免重复提交</a></font><script>window.location.href=&#39;inout.htm&#39;;</script>"; 
} 
else{ 
    echo "<script>window.alert(\"操作失败\");</script><font size=3><a href=inout.htm>请检查你提交的数据是否规范或者联系管理员!!</a></font>";
}
?>
Copy after login

可以在发表页生成个cookie,在提交页,如果提交成功了就把这个cookie清了,这个刷新的时候判断cookie是否存在就可以了

还有和种方法就是查询数据库之后直接判断,

if($regs){ 
    die(&#39;is exisit&#39;); 
}else{ 
    mysql_..... 
}
Copy after login


本文地址:

转载随意,但请附上文章地址:-)

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!