Here is some code you can hack up that should do the trick, I slimmed it
down to make it easier to digest...



<!--- The Form --->
<FORM ACTION="/blah.cfm" METHOD="POST" name="Add">
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tr bgcolor="silver">
<td align="center">Line No</td>
<td align="center">Q P/N</td>
<td align="center">C P/N</td>
</tr>
<tr bgcolor="white">
<td align="center"><INPUT NAME="LineNo1" SIZE="3"></td>
<td align="center"><INPUT NAME="QPart1" SIZE="20"></td>
<td align="center"><INPUT NAME="CPart1" SIZE="20"></td>
</tr>
<tr bgcolor="white">
<td align="center"><INPUT NAME="LineNo2" SIZE="3"></td>
<td align="center"><INPUT NAME="QPart2" SIZE="20"></td>
<td align="center"><INPUT NAME="CPart2" SIZE="20"></td>
</tr>
<tr bgcolor="white">
<td align="center"><INPUT NAME="LineNo3" SIZE="3"></td>
<td align="center"><INPUT NAME="QPart3" SIZE="20"></td>
<td align="center"><INPUT NAME="CPart3" SIZE="20"></td>
</tr>
</table>
</FORM>




<!--- Action Page Stuff --->

<!--- Determine Loop Length For Actual Insert --->
<cfset endloop = 0>
<cfset formno = 1>
<cfloop index="index" from="1" to="3">  <!--- Increase the "to" for how many
rows you have in your form --->
<cfif Evaluate("LineNo" & formno) IS NOT "">
<cfset endloop = endloop +1>
<cfset formno = formno +1>
</cfif>
</cfloop>


<cfloop index="i" FROM="1" TO="#endloop#">

<cfset SingleLineNo = Evaluate("Lineno" & i)>
<cfset SingleQPart = Evaluate("QPart" & i)>
<cfset SingleCPart = Evaluate("CPart" & i)>



<CFQUERY NAME="TheInsert" DATASOURCE="blah">
INSERT INTO blah
(
"line",
"item",
"part"
)
 VALUES
(
'#SingleLineNo#',
'#SingleQPart#',
'#SingleCPart#'
)
</CFQUERY>

</cfif>

</cfloop>




Notes:
Add tests as needed, perhaps to require at least one line of input.
In this process I use LINENO to check if there is another record to insert,
so there
could be a problem if the user skips a line and continues to input, you can
add a test
to the initial loop to handle this.

I also add some tests within the second loop that check if the record exist
or whatever, this may
not be a problem easily added with some CFIF stuff....

Hope it helps, should be a good start or at least give you some idea's....


-Adrian



> -----Original Message-----
> From: Dharmesh Goel [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, October 17, 2000 1:19 PM
> To: CF-Talk
> Subject: Multiple row form data submission to database?
>
>
> Hello Everyone,
>
> I am trying to make a small data entry screen in ColdFusion.
> There are five
> columns in the table. Number of rows is dynamically generated
> with the first
> column automatically filled in. Others have to be filled in by a
> user. When
> the user submits the form, each row is inserted in a database as
> a new row.
>
> I have not done a form submission until now that updates multiple rows. I
> hope you can help me with the basic logic involved in this. My guess would
> be to insert the data from the form into a 2 dimensional Array
> and then loop
> over the array while inserting into the database. How do I insert
> it into an
> array and proceed from there?
>

------------------------------------------------------------------------------------------------
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists or send a message 
with 'unsubscribe' in the body to [EMAIL PROTECTED]

Reply via email to