473,405 Members | 2,373 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 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 5993
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Bruce | last post by:
I have a number of forms that do significant work based on variables POSTed from the form. What is the common method of detecting and preventing this work from being done when the form is POSTed as...
2
by: aboesteanu | last post by:
Data is stored in SQL Server 2000. One table is Person another Item. Each row in the Person table may have associated with it several rows in the Item table. The Item table has a field called...
5
by: Darrel | last post by:
I have a web form that inserts a record into a DB. This function is called from the button_click subroutine. After the record is inserted, I show/hide some different panels and let the page...
9
by: Gummy | last post by:
Hello, I created a user control that has a ListBox and a RadioButtonList (and other stuff). The idea is that I put the user control on the ASPX page multiple times and each user control will...
0
by: Gummy | last post by:
Hello, I have a multiple user controls (15) that are dynamically added to a PlaceHolder everytime the page is loaded. In a listbox on the left (in the user controls), I can select an item, click...
28
by: Peter Michaux | last post by:
Hi, I'm playing with dynamic script insertion to make a request to the server for a JavaScript file to be automatically run when it arrives in the browser. It works but... The page caching...
4
by: AD | last post by:
Hi, I have 2 different web pages, both using RequiredFieldValidator's, on the one page Postbacks are prevented when required fields are blank, on the other page the validators display the error...
7
by: chowdary | last post by:
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.