即使用户多次刷新页面,我也只想更新一次。我该怎么做?
更新unlockedbooks.php
if($quantbuy<=$quantity){
$upd="update books set quantity=quantity-'$quantbuy' where code='$code' ";
mysqli_query($con,$upd);
}
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/>
对于我的问题,更新后使用页眉是个好主意吗?
您可以重定向到填写此表单的页面,也可以重定向到感谢页面,还可以向重定向页面发送一些消息,根据该消息值,您可以显示成功或错误消息,以便填写表单的人知道发生了什么。
所以重定向如下:
header("location:redirection-page-name.php?msg=success");
在重定向的页面上获取消息并显示消息。
您应该在更新后重定向页面
像这个
header('Location:whaterever_your_page.php');
您应该遵循"Post Redirect Get"模式。此外,你最好将你的表单方法改为post。
在books表中再使用一列,如is up_date,并将默认值设置为0,第一次更新后将up_date设置为1。如果up_date=0,则在更新图书表之前检查它,否则不更新图书。