Stop data inserting into a database twice

后端 未结 16 1381
再見小時候
再見小時候 2020-12-01 00:33

I was wondering what methods/preventions other programmers use to stop data being entered twice into a MySQL database when a user refreshes on the same page as a form? Obvio

16条回答
  •  时光说笑
    2020-12-01 01:00

    Ilya's answer is correct, I just wanted to add a little more than would fit in a comment:

    If resubmission is dangerous (going back and submitting again, reloading the result page [if you haven't taken Ilya's advice], etc.) I use a "nonce" to make sure the form can only go through once.

    On the form page:

    
    // ... snip ...
    

    In the processing page:

    After the form has been submitted once, it cannot be submitted again, unless the user intentionally fills it out a second time.

提交回复
热议问题