Updating & Inserting with dynamic data
Hi. I am trying to update and insert some initials I have in drop down menus on a page that has dynamic data. I am able to update the items that have initials in the database already, but I cannot get the insert to work at the same time if another row that has initials chosen and is not in the database yet. For instance if the 3 sets of initials below represent my rows with drop down menus, the bottom 2 are already in the database, so I just update them and I have the code for this working. For the top one, however, I just chose those initials now as I am working on this page, so I need to insert those initials into the database and just update the bottom 2 initials. I'm not sure why my If statement is not working. I have it below. I basically have it saying if the drop down has initials chosen and the APV_ItemID is the row to update, then update the table. Elseif the Initials are chosen and the APV_ItemID is blank or does not exist in the database, then insert those initials. If I remove the APV_ItemID is blank code, then it just inserts both the initials I want it to insert and also inserts the update info. into more rows in the database. It should just update the bottom 2 and insert the top one. What am I doing wrong here? I also have another column called Document Type that tells me if it's a PNR or BOM Request, so I'm not sure if I need that. I commented that out. Can someone help me with this? Thanks.
JC
AG
SN
<cfloop index="id" list="#form.listofids#" delimiters=",">
<cfif structKeyExists(form, "PNR_Approval_Initials#id#") AND form["PNR_Approval_Initials#id#"] NEQ "">
<cfquery Datasource="#application.DataSource#">
Update Approval
Set [Approval_Initials]='#Evaluate("form.PNR_Approval_Initials#id#")#'
Where APV_ItemID=#id#
</cfquery>
<cfelseif structKeyExists(form, "PNR_Approval_Initials#id#") AND form["PNR_Approval_Initials#id#"] NEQ ""<!--- and "Document_Type#id#" EQ "" and "APV_ItemID#id#" EQ "" --->>
<cfquery Datasource="#application.DataSource#">
Insert Into Approval (APV_ItemID,
APV_ECID,
Document_Type,
Approval_Initials)
Values ('#Evaluate("form.ItemID#id#")#',
'#Evaluate("form.ECID#id#")#',
<cfif isDefined ("form.PNR_Document_Type#id#") and
"form.PNR_Document_Type#id#" neq "">
'#Evaluate("form.PNR_Document_Type#id#")#',
<cfelse>
Null,
</cfif>
<cfif isDefined ("form.PNR_Approval_Initials#id#") and
"form.PNR_Approval_Initials#id#" neq "">
'#Evaluate("form.PNR_Approval_Initials#id#")#'
<cfelse>
Null
</cfif>)
</cfquery>
</cfif>
</cfloop>
Andy
