"pantera32" <webforumsuser@macromedia.com> wrote in
message
news:efe8cb$bmb$1@forums.macromedia.com...
> Hello,
>
> I need to insert multiple records into a database from a
form with
> Coldfusion
> and am stuck ? it functions properly when inserting one
record at a time.
> Basically the user will select their employee name
(EmployeeID) from a
> dynamic
> list, and then multiple session numbers (SessionNumber)
which are training
> classes.
Basically you need to append a number to each form field, so
that you have
fields like firstname1, firstname2, etc. Create a hidden
field to hold the
number of total records. Then you can use a loop and evaluate
function to
insert the fields:
<input name="totalrows" value="3" type="hidden" />
<cfloop from="1" to="#form.totalrows#" index="i">
<cfquery datasource="#mydatasource#">
INSERT mytable
(firstname)
VALUES (
'#Evaluate("form.firstname#i#")#'
}
</cfquery>
</cfloop>
There is another way to do it using a list without appending
numbers to the
fields, but it doesn't work with checkboxes.
I wrote an article about it here:
http://www.communitymx.com/content/article.cfm?cid=7B59D
It's free for members, and a small fee for non-members.
--
--
Tom Muck
co-author Dreamweaver MX 2004: The Complete Reference
http://www.tom-muck.com/
Cartweaver Development Team
http://www.cartweaver.com
Extending Knowledge Daily
http://www.communitymx.com/