Skip to main content
Participant
November 23, 2013
Question

Re: insert statement runs twice in place of once

  • November 23, 2013
  • 1 reply
  • 688 views

I am using a insert statement.The insert statement picks a variable

from the form and inserts it into the database

I have no loops in the page the code is :

<cfif isdefined("Form.Category")>

<cfquery name="InsertCat" datasource="ShoppingCart">

Insert Into ShoppingMstCategory(Category)

Values('#Form.Category#')

</cfquery>

</cfif>

The insert runs twice on its own.

Though if I use Query analyser to insert the statement only inserts once.

am I missing something. I am using CF10.

Here's the whole page.

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<title>cat update</title>

</head>


<body>

<cfif isdefined("Form.Category")>

<cfquery name="InsertCat" datasource="ShoppingCart">

Insert Into ShoppingMstCategory(Category)

Values('#Form.Category#')

</cfquery>

<cfelse>

<cfif isdefined("Form.CategoryEdit")>

<cfquery datasource="Shoppingcart">

UPDATE ShoppingMstCategory

SET

[Category] = '#Form.Category#'

WHERE CategoryID = #Form.EditId#

</cfquery>

</cfif>

</cfif>


</body>

</html>

This topic has been closed for replies.

1 reply

BKBK
Community Expert
Community Expert
December 1, 2013

ColdFusion is behaving exactly as it should. When the form is submitted, the variables form.category and form.categoryEdit are both defined. In other words, isdefined("Form.Category") and isdefined("Form.CategoryEdit") are both true. Hence, the if-block as well as the else-block will run.