简体   繁体   English

即使用户再次刷新页面,也如何仅更新一次?

[英]How to update only once even when user refreshes page the page again?

I want to update only once even when the user refreshes the page many times.How can I do that? 即使用户多次刷新页面,我也只想更新一次,该怎么办?

updateunblockedbooks.php updateunblockedbooks.php

if($quantbuy<=$quantity){
    $upd="update books set quantity=quantity-'$quantbuy' where code='$code' ";
    mysqli_query($con,$upd);
}

HTML form page HTML表单页面

<form name="updatebook" action="updateunblockedbooks.php" method="get">
quantity:<br/><input type="number" name="quantbuy" id="quantity" required><br/>
Code:<br/><input type="number" name="code" id="code"><br/>
<input type="submit" value="submit" onclick="return validate2();"><br/>

Is using header after updating a good idea for my question? 在更新我的问题后是否使用标题?

You can redirect to that page where this form is filled from or you can redirect to a thank you page and you can also send some message to the redirection page and according to that message value you can display success or error message so the person filling the form knows what happened. 您可以重定向到填写此表单的页面,也可以重定向到“谢谢”页面,还可以向重定向页面发送一些消息,并根据该消息值可以显示成功或错误消息,以便填写此表单的人表格知道发生了什么。

So redirect like this: 所以像这样重定向:

header("location:redirection-page-name.php?msg=success");

And on the page where this redirects to get that msg and display message. 并在此重定向到的页面上获取该味精并显示消息。

you should redirect your page after update 您应该在更新后重定向页面

like this 像这样

header('Location:whaterever_your_page.php');

You should follow the "Post-Redirect-Get" pattern. 您应该遵循“ Post-Redirect-Get”模式。 In addition, you'd better change your form method to post. 另外,最好将表单方法更改为post。

在books表中再使用一列,如up_dated,并将默认值设置为0,并在首次更新后将up_dated设置为1。如果up_dated = 0,则在更新book表之前对其进行检查,否则不进行更新。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM