-1

Hello I made a form in php with db in mysql and when I use it works but when I reload the page send the data I send previously and the records are duplicated please can you help me?

some images: that's how the form looks

this is the code: code

douglas
  • 111
  • 1
  • 8

1 Answers1

0

Send 303 code on the same page to the client after first submit, client won't be able to submit it again with "reload" button.

header("Location: $url", true, 303); die; # where $url is your page
user1597430
  • 1,138
  • 1
  • 7
  • 14
  • Is that the connection string? – douglas Oct 15 '17 at 16:57
  • @douglas, not sure what you are talking about. – user1597430 Oct 15 '17 at 16:58
  • this is my connection string: – douglas Oct 15 '17 at 16:59
  • @douglas nope, it's HTTP header builder. Code above redirects client to another page (or same page) with a help of HTTP 303 code to clean submitted data from client's side. You have to place it in the end of your main logic, e.g. after your last mysql insert. – user1597430 Oct 15 '17 at 17:01
  • $url="reserva.php"; header("Location: $url", true,303); die; // it's okay ? now in firefox I get a message "The page isn’t redirecting properly Firefox has detected that the server is redirecting the request for this address in a way that will never complete. This problem can sometimes be caused by disabling or refusing to accept cookies." – douglas Oct 15 '17 at 17:13
  • @douglas add a hidden field (``````) in your form, and insert ```header("Location: ...")``` into the ```if (isset($_REQUEST['submit'])) { ... }``` statement to prevent endless redirect from the same page to the same page. – user1597430 Oct 15 '17 at 17:17
  • Try but stay the same :( – douglas Oct 15 '17 at 17:29
  • @douglas no code - no ideas what did you wrong – user1597430 Oct 15 '17 at 17:30
  • Thank you! now it works for me just had to put it inside the code but now does not run the confirmation script e.e – douglas Oct 15 '17 at 18:07