Home >Backend Development >PHP Tutorial >How to prevent repeated data insertion when refreshing the web page_PHP tutorial

How to prevent repeated data insertion when refreshing the web page_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:51:45935browse

There are many and very simple methods on how to prevent repeated data insertion when refreshing the web page. Below we will provide several reference processing methods.

There are many and very simple methods on how to prevent repeated data insertion when refreshing the web page. Below we will provide several reference processing methods.

How to prevent refreshing the web page from inserting data
I made a message board, but information will be inserted every time I refresh it. How can I prevent data from being inserted after refreshing?

JS returns after each operation
$regs=mysql_query($shouruinsert,$conn);
if($regs) echo "<script>window.alert("Operation successful");</script>Your income has been stored, please Return. Do not refresh this page to avoid repeated submission<script>window.location.href='inout.htm';</script>";
}
else{
echo "<script>window.alert("Operation failed");</script> Please check whether the data you submitted is standardized or contact the administrator! !";}

You can generate a cookie on the publishing page. On the submission page, if the submission is successful, the cookie will be cleared. When refreshing, just determine whether the cookie exists

Another method is to directly determine after querying the database,

if($regs){

die('is exisit');

}else{

mysql_.....

}

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632538.htmlTechArticleThere are many and very simple methods on how to prevent repeated data insertion when refreshing the web page. Below we will provide several references. How to deal with it. Regarding how to prevent repeated data insertion when refreshing the web page...
Statement:
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