471,336 Members | 1,280 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,336 software developers and data experts.

Preventing multiple data insertion on page reload

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
Jul 17 '05 #1
3 5905
Raju V.K <ra****@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.
Jul 17 '05 #2
ra****@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/
Jul 17 '05 #3
Raj Shekhar wrote:
ra****@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/

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

Regards,
Raju

Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by aboesteanu | last post: by
5 posts views Thread by Darrel | last post: by
28 posts views Thread by Peter Michaux | last post: by
4 posts views Thread by AD | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.