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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Duplicating Insert

Status
Not open for further replies.

btgroup

MIS
Jan 21, 2003
64
US
Hello,

I have some ColdFusion code that seems to be duplicating my insert statement (running it twice). Can someone please take a look and let me know where my problem lies? It is driving me crazy. Could this be a server setting?

<cftry>
<cfset variables.strErr = &quot;&quot;>
<cfif (variables.strName eq &quot;&quot;)>
<cfset variables.strErr = &quot;1&quot;>
<cfthrow>
</cfif>
<cfif variables.strErr eq &quot;&quot;>
<cftry>
<CFQUERY name=&quot;rs&quot; datasource=&quot;datasource&quot;>
INSERT vendors(name)
VALUES('#variables.strName#')
</CFQUERY>
<cfcatch>
<cfset variables.strErr = &quot;4&quot;>
<cfthrow>
</cfcatch>
</cftry>
<cflocation url=&quot;../vendors/vendors.cfm?Action=completevendoradd&quot;><cfabort>
</cfif>
<cfcatch>
<form name=&quot;frmVendorAdd&quot; method=&quot;post&quot; action=&quot;./vendors.cfm?Action=add&err=<cfoutput>#variables.strErr#</cfoutput>&quot;>
<input type=&quot;hidden&quot; name=&quot;txtName&quot; value=&quot;<cfoutput>#variables.strName#</cfoutput>&quot;>
<input type=&quot;Submit&quot; name=&quot;Submit&quot; value=&quot;Submit&quot;>
</form>
<script language=&quot;JavaScript&quot;>document.frmVendorAdd.submit();</script><cfabort>
</cfcatch>
</cftry>
 
Well, just in case someone runs across a similar issue. The problem I was having was not in the code snippet provided, which is only run after my form is submitted.

I had the following form submission
<input type=&quot;Submit&quot; name=&quot;Submit&quot; value=&quot;Add Vendor&quot; onClick=&quot;if(this.value == 'Add Vendor') this.form.submit(); this.value = 'Please Wait';&quot;>

Since the type is Submit and my onClick event also submits the form, the form was being submitted twice, and therefore inserts the values twice.

Lesson learned. D'oh!!!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top