简体   繁体   中英

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

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

HTML form page

<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. In addition, you'd better change your form method to post.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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