Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
PHP How-To Post your "How do I do this with PHP?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old August 18th, 2004, 03:32 PM
Authorized User
Join Date: Sep 2003
Location: , , .
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default page Refresh

I have a submit button that processes a sql insert statement. How do I prevent the statment from resubmitting itself when the user refreshes the page with either an F5 or with the IE refresh option?

Old August 18th, 2004, 03:38 PM
Friend of Wrox
Join Date: Nov 2003
Location: , , .
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts

The simplest solution is to make it submit to another page, and then redirect to the first page.

Otherwise, you can check to see if an identical row already exists in the database and only enter a row if there isn't.



Old August 25th, 2004, 04:03 AM
richard.york's Avatar
Wrox Author
Points: 5,506, Level: 31
Points: 5,506, Level: 31 Points: 5,506, Level: 31 Points: 5,506, Level: 31
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Jun 2003
Location: Camby, IN, USA.
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts

If the row has a unique id, place that unique id in a session variable.

if (!isset($_SESSION['this_form_name_is_submitted']))
  // do form processing
  // insert query
  $_SESSION['this_form_name_is_submitted'] = mysql_insert_id();
  // you already submitted!

That's the easiest way I could think to do it. Of course you don't have to use the insert id at all, a simple boolean will do, but that might have other useful applications.


[http://pear.php.net/Mail_IMAP] A PHP/C-Client/PEAR solution for webmail

Similar Threads
Thread Thread Starter Forum Replies Last Post
Error when refresh the page! heba ASP.NET 2.0 Professional 3 June 6th, 2007 08:32 AM
Parent Page Refresh crmProg Visual Studio 2005 1 February 9th, 2007 09:56 AM
How to refresh parent page amolpayal Javascript How-To 1 August 2nd, 2006 05:03 AM
Need to "Refresh" page fskilnik Dreamweaver (all versions) 3 October 20th, 2005 10:49 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.