For Programmers: Free Programming Magazines  


Home > Archive > PHP Programming > January 2005 > Preventing multiple data insertion on page reload









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Preventing multiple data insertion on page reload
Raju V.K

2005-01-28, 3:57 pm

I am developing a PHP-mysql database. It is noted that when the
browser window is refreshed the data is inserted again in the
database. unfortunately there is no unique keys that I can use to
verify the existance of the data, so as to prevent the multiple
insertion. Is there any other way to prevent it otherthan introducing
another field for this purpose and verifying its existance?


Regards,

Raju
Daniel Tryba

2005-01-28, 3:57 pm

Raju V.K <rajuvk@satyam.net.in> wrote:
> I am developing a PHP-mysql database. It is noted that when the
> browser window is refreshed the data is inserted again in the
> database. unfortunately there is no unique keys that I can use to
> verify the existance of the data, so as to prevent the multiple
> insertion. Is there any other way to prevent it otherthan introducing
> another field for this purpose and verifying its existance?


While that may be the best way, I often simply redirect
(header/location) after manipulating data. A browser can still go back a
couple of pageviews and refresh to reinsert the data but it is
sufficient for most purposed I think.
Raj Shekhar

2005-01-28, 3:57 pm

rajuvk@satyam.net.in (Raju V.K) writes:

> I am developing a PHP-mysql database. It is noted that when the
> browser window is refreshed the data is inserted again in the
> database. unfortunately there is no unique keys that I can use to
> verify the existance of the data, so as to prevent the multiple
> insertion. Is there any other way to prevent it otherthan introducing
> another field for this purpose and verifying its existance?


You can use session variables to flag that the insert operation has
occurred once. i.e.

if (!isset($_SESSION["PAGE_NAME_INSERT"]))
{
/* Do the insertion operation */
$_SESSION["PAGE_NAME_INSERT"]=true;
}

else
{

/* The value have already been inserted. */

}

Note that at the page which sends the data to the page which actually
does the insertion, you might want to unset the
$_SESSION["PAGE_NAME_INSERT"] variable. This is needed if the user
presses "Back" and then changes some values in the form and resubmits.

--
Raj Shekhar
System Administrator, programmer and slacker
home : http://rajshekhar.net
blog : http://rajshekhar.net/blog/
rajuvk@satyam.net.in

2005-01-29, 3:55 am

Raj Shekhar wrote:
> rajuvk@satyam.net.in (Raju V.K) writes:
>
introducing[color=darkred]
>
> You can use session variables to flag that the insert operation has
> occurred once. i.e.
>
> if (!isset($_SESSION["PAGE_NAME_INSERT"]))
> {
> /* Do the insertion operation */
> $_SESSION["PAGE_NAME_INSERT"]=true;
> }
>
> else
> {
>
> /* The value have already been inserted. */
>
> }
>
> Note that at the page which sends the data to the page which actually
> does the insertion, you might want to unset the
> $_SESSION["PAGE_NAME_INSERT"] variable. This is needed if the user
> presses "Back" and then changes some values in the form and

resubmits.
>
> --
> Raj Shekhar
> System Administrator, programmer and slacker
> home : http://rajshekhar.net
> blog : http://rajshekhar.net/blog/



This is a good suggestion, as it does not make a database request. I
will give it a try.

Regards,
Raju

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com