New row inserted for each page refresh

后端 未结 5 933
别那么骄傲
别那么骄傲 2021-01-15 03:27

Hi I\'m getting a strange problem while inserting records into database. In my button click event I\'m trying to insert some values into my database it is working fine. Once

5条回答
  •  遥遥无期
    2021-01-15 03:42

    It's happening because you're requesting the page again, using the same POST parameters that were used to request it the first time.

    To fix it: either check for a page refresh in your code and don't do the insert in that event, or set a cookie the first time, and then don't do the insert again if the cookie is there. The cookie could either have a fixed duration (say 30 minutes), or it could be a session cookie, which would last until the users closes the browser.

提交回复
热议问题