Link to home
Start Free TrialLog in
Avatar of erikTsomik
erikTsomikFlag for United States of America

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.categoryname)#">
                       <cfset variables.thisCheckbox = ListGetAt(form.categoryname,variables.i)>
           <cftry>
                   <cfstoredproc procedure="addCategory" datasource="HotBanana_Manager">
                            <cfprocparam type="in" cfsqltype="cf_sql_varchar" value="#variables.thisCheckbox#">        
                      <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>
Avatar of siva_siva
siva_siva
Flag of India image

Check condition using unique id before inserting a record whether it is already inserted or not.
Avatar of erikTsomik

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.
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>
ASKER CERTIFIED SOLUTION
Avatar of _agx_
_agx_
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial