Refreshing the webpage again adds data to the DB

I have a php webpage with a form. After filling out the form on the web page, I can send it to the server. But after that, if I refresh the page, it inserts the same record into the database. Are there any solutions to this problem?

+5
source share
7 answers

Use the POST / Redirect / GET pattern . This will not allow the user to resubmit the same form.

+9
source

There are several ways, for example:

  • Create the token that you insert into the form (hidden field). if the same token is sent twice, cancel the second submit.
  • , .
  • .
  • , Post/Redirect/Get pattern ( ).
+4

, . , , - , . , , , .

+1

, , Refresh : " ".

, , , . , .

+1

, , , , , . . , " " " " "".

, , .

0

process.php action.

process.php

//code to insert item to database
header('Location: YOUR_FORM_PAGE_HERE);

0

INSERT IGNORE INTO table_name ...

.

-1

All Articles