簡體   English   中英

即使用戶再次刷新頁面,也如何僅更新一次?

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

即使用戶多次刷新頁面,我也只想更新一次,該怎么辦?

updateunblockedbooks.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表中再使用一列,如up_dated,並將默認值設置為0,並在首次更新后將up_dated設置為1。如果up_dated = 0,則在更新book表之前對其進行檢查,否則不進行更新。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM