Home >Backend Development >PHP Tutorial >How to prevent repeated data insertion when refreshing the web page_PHP tutorial
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_.....
}