Using cfloop to update and/or add data?
I am using this code from a tutorial on the web to add multiple records to a database. These records are linked to another table by ProductID, in other words there could be many records generated by this form but they will all have the same ProductID number coinciding with the one ProductID in the other table. Here is my issue, I need an update page for these records that will allow me to update existing records or add additional ones. I am new to using cfloop and was able to get the original code to function correctly but can't figure out how to code this for update. Any help would be appreciated.
Here is the code:
<cfif isdefined ("form.number")>
<cfset getnumber = form.number + 1>
<cfelse>
<cfset getnumber = 1>
</cfif>
<cfif getnumber GT 1>
<cfset focusonme = " document.all.osform.CFSNumber" & getnumber & ".focus();">
<cfelse>
<cfset focusonme = "document.all.osform.CFSNumber.focus();">
</cfif>
<cfoutput>
<script type="text/javascript">
function dofocusthing(){
#focusonme#
}
function submitform(){
document.all.osform.action = 'act_add.cfm';
document.all.osform.submit();
}
function getnewline(){
document.all.osform.action = 'add_products.cfm';
document.all.osform.submit();
}
</script>
</cfoutput>
<body onLoad="javascript:dofocusthing();">
<table width="80%" rules="none" align="center">
<tr>
<td>CFSNumber</td>
<td>MfgPart</td>
<td>Pack</td>
<td>Pallet-Case</td>
<td>Size</td>
</tr>
<cfoutput>
<input type="hidden" name="number" value="#getnumber#">
<cfloop from="1" to="#getnumber#" index="idx">
<tr>
<cfif isdefined ("form.CFSNumber#idx#")>
<td><input type="text" name="CFSNumber#idx#" value="#evaluate("form.CFSNumber#idx#")#"></td>
<cfelse>
<td><cfinput type="text" name="CFSNumber#idx#"></td>
</cfif>
<cfif isdefined ("form.MfgPart#idx#")>
<td><cfinput type="text" name="MfgPart#idx#" value="#evaluate("form.MfgPart#idx#")#"></td>
<cfelse>
<td><cfinput type="text" name="MfgPart#idx#"></TD>
</cfif>
<cfif isdefined ("form.Pack#idx#")>
<td><cfinput type="text" name="Pack#idx#" value="#evaluate("form.Pack#idx#")#"></td>
<cfelse>
<td><cfinput type="text" name="Pack#idx#"></td>
</cfif>
<cfif isdefined ("form.PalletCase#idx#")>
<td><cfinput type="text" name="PalletCase#idx#" value="#evaluate("form.PalletCase#idx#")#"></td>
<cfelse>
<td><cfinput type="text" name="PalletCase#idx#"></td>
</cfif>
<cfif isdefined ("form.Size#idx#")>
<td><cfinput type="text" name="Size#idx#" value="#evaluate("form.Size#idx#")#"></td>
<cfelse>
<td><cfinput type="text" name="Size#idx#"></td>
</cfif>
</tr>
</cfloop>
</cfoutput>
<tr>
<td colspan="8"><input type="button" name="add" value="Add Line onClick="javascript:getnewline();"></td>
</tr>
</table>
<table width="90%" align="center">
<tr>
<td> </td>
</tr>
</table>
And the action page:
<cfloop from="1" to="#form.number#" index="idx">
<cfset getCFSNumber = evaluate("form.CFSNumber" & idx)>
<cfset getMfgPart = evaluate("form.MfgPart" & idx)>
<cfset getPack = evaluate("form.Pack" & idx)>
<cfset getPalletCase = evaluate("form.PalletCase" & idx)>
<cfset getSize = evaluate("form.Size" & idx)>
<cfquery name="addSubProducts" datasource="farmky">
insert into SubProduct (CFSNumber,MfgPart,Pack,PalletCase,Size)
values (#getCFSNumber#,'#getMfgPart#','#getPack#','#getPalletCase#','#getSize#')
</cfquery>
</cfloop>
