erikTsomik
asked on
Avoiding save record while refresh after submit in coldfusion
In my form I have a drop down with list of program. Also I have an add optioon , so once the user click on it I will get the text field and a radio button where the user would enter all the info in click on save submit. That will start the insert SP. So my question is once I do the submit I will get duplicate records in the database. How can I avoid duplicate submittion. Here is my CF code
<cfparam name="form.hidden" default="0">
<cfparam name="form.categoryname" default="">
<cfif isDefined("form.btnsubmit3 ")>
<cfloop index="variables.i" from="1" to="#ListLen(form.category name)#">
<cfset variables.thisCheckbox = ListGetAt(form.categorynam e,variable s.i)>
<cftry>
<cfstoredproc procedure="addCategory" datasource="HotBanana_Mana ger">
<cfprocparam type="in" cfsqltype="cf_sql_varchar" value="#variables.thisChec kbox#">
<cfprocparam type="in" cfsqltype="cf_sql_varchar" value="#session.schoolcode #">
<cfprocparam type="in" cfsqltype="cf_sql_bit" value="#form.hidden#">
</cfstoredproc>
<cfcatch type="database">
There was a database error!
</cfcatch>
</cftry>
</cfloop>
</cfif>
<cfparam name="form.hidden" default="0">
<cfparam name="form.categoryname" default="">
<cfif isDefined("form.btnsubmit3
<cfloop index="variables.i" from="1" to="#ListLen(form.category
<cfset variables.thisCheckbox = ListGetAt(form.categorynam
<cftry>
<cfstoredproc procedure="addCategory" datasource="HotBanana_Mana
<cfprocparam type="in" cfsqltype="cf_sql_varchar"
<cfprocparam type="in" cfsqltype="cf_sql_varchar"
<cfprocparam type="in" cfsqltype="cf_sql_bit" value="#form.hidden#">
</cfstoredproc>
<cfcatch type="database">
There was a database error!
</cfcatch>
</cftry>
</cfloop>
</cfif>
Check condition using unique id before inserting a record whether it is already inserted or not.
ASKER
The id automatically generated so there is no way to check it.
In that form any other unique is present other than auto increment id. If no means you cannot avoid that problem. Because its not a language problem. You only set one unique name other than auto increment id.
ASKER
I can use category name
<cfquery name="exist" datasource="test">
select * from example category_name = #category_name#
</cfquery>
<cfif exist.recordcount GT 0>
Already exists
<cfelse>
Insert code here
</cfif>
select * from example category_name = #category_name#
</cfquery>
<cfif exist.recordcount GT 0>
Already exists
<cfelse>
Insert code here
</cfif>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.