Author Topic: Time limit between posts/entries into db  (Read 3911 times)

Canuck

  • Eh?!!
  • Founders
  • Posts: 792
  • Karma: +51/-3
  • Andy Moog Fan
    • My Website
Time limit between posts/entries into db
« on: October 09, 2007, 11:21:39 PM »
I am working on a site where users fill in a form, and when submitted, a table is updated.

If you continue to refresh the page where an entry is submitted it continues to add the entry to the database. What is the best way to prevent this?

Thanks!

Steve

  • This 49%er supports Romney
  • Just a Jackass
  • *
  • Posts: 16120
  • Karma: +31/-410
  • Mr. Mom
Re: Time limit between posts/entries into db
« Reply #1 on: October 09, 2007, 11:56:18 PM »
i had that problem with a html submission form i did not that long ago. the helpful links i came across were these two

http://www.web-source.net/web_development/form_submission.htm
http://www.elated.com/articles/preventing-multiple-form-submits/
hey ethic if you and i were both courting lily allen..... oh wait, which one of us has a relationship that lasted more than the bus ride home?

Mike

  • Jackass In Charge
  • Posts: 11257
  • Karma: +168/-32
  • Ex Asshole - a better and more caring person.
Re: Time limit between posts/entries into db
« Reply #2 on: October 10, 2007, 01:01:31 AM »
I am working on a site where users fill in a form, and when submitted, a table is updated.

If you continue to refresh the page where an entry is submitted it continues to add the entry to the database. What is the best way to prevent this?

Thanks!
Don't let them sit on the page that does the actual submission.  Do the work and then send them away.  You can also setup an ID (unique for every page load) for the submission and then keep track of ones that went into the database.

Perspective

  • badfish
  • Jackass In Charge
  • Posts: 4635
  • Karma: +64/-22
    • http://jeff.bagu.org
Re: Time limit between posts/entries into db
« Reply #3 on: October 10, 2007, 12:59:15 PM »
I am working on a site where users fill in a form, and when submitted, a table is updated.

If you continue to refresh the page where an entry is submitted it continues to add the entry to the database. What is the best way to prevent this?

Thanks!
Don't let them sit on the page that does the actual submission.  Do the work and then send them away.  You can also setup an ID (unique for every page load) for the submission and then keep track of ones that went into the database.

Or just make the key the primary key of the table so subsequent inserts fail silently.

ober

  • Ashton Shagger
  • Ass Wipe
  • Posts: 14310
  • Karma: +73/-790
  • mini-ober is taking over
    • Windy Hill Web Solutions
Re: Time limit between posts/entries into db
« Reply #4 on: October 10, 2007, 02:57:01 PM »
I normally go with Mike's idea.  Have a page that does the dirty work and then forwards them to the final destination when complete.

Steve

  • This 49%er supports Romney
  • Just a Jackass
  • *
  • Posts: 16120
  • Karma: +31/-410
  • Mr. Mom
Re: Time limit between posts/entries into db
« Reply #5 on: October 10, 2007, 03:12:08 PM »
Like a processing page? Not a bad idea
hey ethic if you and i were both courting lily allen..... oh wait, which one of us has a relationship that lasted more than the bus ride home?

charlie

  • Jackass In Charge
  • Posts: 7903
  • Karma: +84/-53
Re: Time limit between posts/entries into db
« Reply #6 on: October 10, 2007, 03:57:42 PM »
What if they use "back" to go back to that processing page, will it re-add the stuff to the database?

micah

  • A real person, on the Internet.
  • Ass Wipe
  • Posts: 6915
  • Karma: +58/-55
  • Truth cannot contradict truth.
    • micahj.com
Re: Time limit between posts/entries into db
« Reply #7 on: October 10, 2007, 05:00:21 PM »
here's what i do to solve that problem (on a page the processes credit cards)

PAGE A: on the page where the user enters their card information; on load, make sure they can use sessions.  set something like $_SESSION['ok_to_process'] = true;

then on the page that actually processes the card info have
PAGE B:
Code: [Select]
<?php

if($_SESSION['ok_to_process'] && !isset($_SESSION['already_processed'])){

//... process their card

 
$_SESSION['already_processed'] = true// or this could be their confirmation number or some other value

//then forward them to the confirmation page.
header("Location: PAGE_C.html");
}
?>

now, if they go back to the processing page it wont process their card again because the only way the script will work is if they came to the page from PAGE A  and they haven't already had their card processed.
"I possess a device, in my pocket, that is capable of accessing the entirety of information known to man.  I use it to look at pictures of cats and get in arguments with strangers."

Mike

  • Jackass In Charge
  • Posts: 11257
  • Karma: +168/-32
  • Ex Asshole - a better and more caring person.
Re: Time limit between posts/entries into db
« Reply #8 on: October 10, 2007, 08:59:18 PM »
What if they use "back" to go back to that processing page, will it re-add the stuff to the database?
If you are smart about the redirection then it will go back to the form page and not the work page.

Or just make the key the primary key of the table so subsequent inserts fail silently.
IMO the primary key should be related to the data and not for use with form processing.  Plus doing that leaves you wide open for a nice little DOS attack to the DB server.

Canuck

  • Eh?!!
  • Founders
  • Posts: 792
  • Karma: +51/-3
  • Andy Moog Fan
    • My Website
Re: Time limit between posts/entries into db
« Reply #9 on: October 11, 2007, 10:51:33 PM »
Thanks for the suggestions, Ill look into it this weekend and ask if I have any more issues.

Thanks!