0

I have 3 pages:

  1. index.php: form, method = post, action = "show.php".

  2. functions.php: function with form processing (adding to database).

  3. show.php: table filled with data which is entered in form and with data fetched from database.

show.php includes functions.php

The problem is the Confirm Form Resubmission message appearing when refreshing page F5 in show.php.

Redirecting back to index.php using header() and exit() leads to infinite loop.

Method 2: Post + Redirect to self doesn't work for me.

Form on Page1 posts the data to Page2, Page2 processes the data and does what needs to be done, and then it does a HTTP redirect on itself. This way the last "action" the browser remembers is a simple GET on page2, so the form is not being resubmitted upon F5.

If PRG pattern can help resolving this issue what steps do I need to do in this case? If no, what can you advice to do?

aysee
  • 121
  • 10
  • which one is table.php ? – apokryfos Jun 12 '18 at 15:26
  • @apokryfos, I'm sorry, made a typo, updated my question – aysee Jun 12 '18 at 15:29
  • instead of refreshing page by F5, hit the enter button by highlighting the url in the browser – sree Jun 12 '18 at 15:30
  • You should separate the logic between adding to the database and showing the data. Your form should direct to something that uses functions.php to insert to the database and then redirects to show.php to display the data from the database. – apokryfos Jun 12 '18 at 15:32
  • 1
    @sree, well, this doesn't cause resubmission alert. What can be inferred from that?.. – aysee Jun 12 '18 at 15:34
  • The PRG solution is right - your implementation is wrong, because infinite loop shouldn't happen. You just need condition (or route split) there checking if same script receives POST or GET request (and simply display on GET). – shudder Jun 12 '18 at 15:40
  • @sree that doesnt fix anything, we know we can do that – delboy1978uk Jun 12 '18 at 15:41
  • @shudder, sorry, didn't quite understand. Could you, if you do not mind, give a short example? – aysee Jun 12 '18 at 15:46
  • There should be either separate scripts for `show.php` and `post.php` or the redirect (GET after adding data) should happen only when goint go `show.php` with POST request. `if ($_SERVER['REQUEST_METHOD'] === 'POST') { ....add and redirect ... } else { ...display... }` – shudder Jun 12 '18 at 19:09
  • @shudder, I'm a bit confused, because I already use 2 separate scripts: show.php and functions.php (included to the first one)... – aysee Jun 12 '18 at 19:37
  • Post.php should redirect to index afetr data is added – shudder Jun 13 '18 at 16:40

0 Answers0