Prev: Touch an entry of a zip archive.
Next: How to prevent duplicate record insertion afterrefreshing php page
From: Deva on 19 May 2010 08:13 Hi, If I do refresh after submission of a form, records are getting stored multiple times. I have two pages. /submission-form/ and /thank-you/ I was trying header('Location: /thank-you/'); on submission-form page after successful validation and insertion into db. Still if I do refresh on thank-you page it adds one more record in database. How to prevent it without token? -- Devendra Jadhav दà¥à¤µà¥à¤à¤¦à¥à¤° à¤à¤¾à¤§à¤µ
From: Deva on 19 May 2010 08:23 Yeah... Done... Got the solution... You need to do exit(0); after the header().. die() wont work... On Wed, May 19, 2010 at 5:42 PM, Ashley Sheridan <ash(a)ashleysheridan.co.uk>wrote: > On Wed, 2010-05-19 at 17:43 +0530, Deva wrote: > > Hi, > > If I do refresh after submission of a form, records are getting stored > multiple times. > I have two pages. /submission-form/ and /thank-you/ > I was trying header('Location: /thank-you/'); on submission-form page after > successful validation and insertion into db. Still if I do refresh on > thank-you page it adds one more record in database. > How to prevent it without token? > > > > > > Before inserting the data, perform a query that asks for the count of > records with that data in it. If you get a record, then don't insert the > data. This assumes that the data in the row is always unique. If it's > something like adding a stats record, then have some sort of time comparison > against the current time and the date entry of the latest matching record.. > > Thanks, > Ash > http://www.ashleysheridan.co.uk > > > -- Devendra Jadhav दà¥à¤µà¥à¤à¤¦à¥à¤° à¤à¤¾à¤§à¤µ
From: Peter Lind on 19 May 2010 08:30
On 19 May 2010 14:23, Deva <devendra.in(a)gmail.com> wrote: > Yeah... Done... Got the solution... > You need to do exit(0); after the header().. > die() wont work... > That's rather odd, according to the docs die() and exit() are equivalent. You're sure nothing else changed? Also, note that you should consider using form tokens, so you don't get caught by double submits and cross site form posts, etc. Regards Peter -- <hype> WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind Flickr: http://www.flickr.com/photos/fake51 BeWelcome: Fake51 Couchsurfing: Fake51 </hype> |