?
Solved

Avoiding save record while refresh after submit in coldfusion

Posted on 2007-10-11
6
Medium Priority
?
410 Views
Last Modified: 2013-12-24
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>
0
Comment
Question by:erikTsomik
  • 3
  • 2
6 Comments
 
LVL 5

Expert Comment

by:siva_siva
ID: 20058592
Check condition using unique id before inserting a record whether it is already inserted or not.
0
 
LVL 19

Author Comment

by:erikTsomik
ID: 20058664
The id automatically generated so there is no way to check it.
0
 
LVL 5

Expert Comment

by:siva_siva
ID: 20058721
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.
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
LVL 19

Author Comment

by:erikTsomik
ID: 20058740
I can use category name
0
 
LVL 5

Expert Comment

by:siva_siva
ID: 20058787
<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>
0
 
LVL 52

Accepted Solution

by:
_agx_ earned 2000 total points
ID: 20067002
As I see it, there seem to be two issues

1) Its sounds as if you're running a stored procedure when you shouldn't be.  If the code is behaving incorrectly, you need to change the conditions so it executes at the right time.  Otherwise, you're generating database activity when its not needed.  

2) If duplicates are not allowed, your stored procedure should anticipate this and handle that condition.  In other words, only insert a record if one does not already exist.  

      INSERT INTO TableName (someColumn)
     SELECT  @someVariable ....
     WHERE NOT EXISTS (
                    SELECT 1
                    FROM    SomeTable
                    WHERE  SomeColumn = @someValue
      )
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I spent nearly three days trying to figure out how incorporate OAuth in Coldfusion for the Eventful API. Hopefully, this article will allow Coldfusion Programmers to buzz through the API when they need to. Basically, what this script does is authori…
Originally, this post was published on Monitis Blog, you can check it here . It goes without saying that technology has transformed society and the very nature of how we live, work, and communicate in ways that would’ve been incomprehensible 5 ye…
The purpose of this video is to demonstrate how to manually back up a WordPress Database. This will be demonstrated using a Windows 8 PC. The Host used will be IPage.com Log into your Hosting account. IPage will be used for demonstration : Locat…
The purpose of this video is to demonstrate how to reset a WordPress password if you are locked out and cannot reset the password. A typical use would be if you cannot access the email to which WordPress would send the password recovery email to…
Suggested Courses

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question