Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

inserting data into database 1

Status
Not open for further replies.

peter11

Instructor
Mar 16, 2001
334
US
I am using a form to insert names in to a database. The problem occurs when the user enters the name and while they are on the action page they hit the refresh button.
The data gets inserted again and I end up with duplicate names.

Is there a way to prevent this from happening?
 
What i tend to do is to have an action page that is invisible to the user so that all of the code is processed and then when it is all done move onto another page, using CFLOCATION

So you would have your form page (page1) that submits to the action page (page2) which then transfers to another page confirming what has happened. The user can refresh this page all they like the data will only be inserted by the previous page !

hope this helps !
 
Maybe you could check on duplicate entries
Query checkdupe checks for duplicates
If 'checkdupe' return a record -> update the record (or do nothing, whatever you want). Else insert the record.

<cfquery name=&quot;checkdupe&quot; datasource=&quot;datasource&quot;>
select fieldname
from table
where fieldname = '#form.name#'
</cfquery>

<cfif checkdupe>
.. update query, do nothing
<cfelse>
.. insert query
</cfif>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top