Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Insert multiple rows with one submit

Status
Not open for further replies.

bboult10

MIS
Joined
Nov 9, 2001
Messages
6
Location
CH
can someone please help? I would like to add multiple rows to a table with one submitt button. A new key will also have to be generated for each new addition. Here is my code so far.

<!--- page1: form.cfm///////////////////////////////////////// --->

<FORM name=&quot;form&quot; method=&quot;post&quot; action=&quot;save.cfm&quot;>

<cfoutput><input type=&quot;hidden&quot; name=&quot;RecordCount&quot; value=&quot;#q_interests.RecordCount#&quot;></cfoutput>

<cfloop index=&quot;i&quot; from=&quot;1&quot; to=&quot;#q_interests.RecordCount#&quot;>

<CFQUERY name=&quot;qr_max&quot; datasource=&quot;#application.datasource#&quot; password=&quot;#application.password#&quot; username=&quot;#application.user#&quot;>
exec qry_max
</CFQUERY>

<cfset max_key=#qr_max.COMPUTED_COLUMN_1#+i>

<cfoutput><input type=&quot;text&quot; name=&quot;column1_key&quot; value=&quot;#max_key#&quot;></cfoutput>

</cfloop>

<cfoutput query=&quot;qr_selected_entities&quot;>
<table>
<tr>
<td width=&quot;30%&quot; valign=&quot;top&quot;><input type=&quot;text&quot; name=&quot;column2&quot; value=&quot;#q_names.username#&quot;></td>
<td width=&quot;30%&quot; valign=&quot;top&quot;><input type=&quot;text&quot; name=&quot;column3&quot; value=&quot;#q_interests.interest#&quot;></td>
</tr>
</table>
</cfoutput>
<input type=&quot;submit&quot; value=&quot;Submitt&quot; style=&quot;BACKGROUND-COLOR: rgb(173,189,222); COLOR: black; FONT-SIZE: 1pt&quot;>
</form>

<!--- page2 save.cfm///////////////////////////////////////// --->

<cfloop index=&quot;i&quot; from=&quot;1&quot; to=&quot;#form.RecordCount#&quot;>

<cfset loc_column1_key = &quot;form.column1_key&quot; & i>
<cfset loc_column2 = &quot;form.column2&quot; & i>
<cfset loc_column3 = &quot;form.column3&quot; & i>

<cfquery name=&quot;qryAddList#i#&quot; datasource=&quot;#application.datasource#&quot; password=&quot;#application.password#&quot; username=&quot;#application.user#&quot;>
INSERT into savedtable
(key, username, interest)
VALUES
(#Evaluate(loc_column1_key)#, '#Evaluate(loc_column2)#', 2, #Evaluate(loc_column3)#)
</cfquery>

</cfloop>
 
Hey .. here's a sample code that works .. it basically inserts 5 last names and 5 firsnames at once ...

THIS IS THE FORM PAGE::
<form mehod=&quot;post&quot; action=&quot;test2.cfm&quot;>
<p>First Name:
<input type=&quot;TEXT&quot; Name=&quot;fname1&quot;>
<br>
Last Name:
<Input type=&quot;Text&quot; Name=&quot;lname1&quot;>
<p>
<input type=&quot;hidden&quot; name=&quot;jobcode1&quot; >

<p>First Name:
<input type=&quot;TEXT&quot; Name=&quot;fname2&quot;>
<br>
Last Name:
<Input type=&quot;Text&quot; Name=&quot;lname2&quot;>
<p>First Name:
<input type=&quot;TEXT&quot; Name=&quot;fname3&quot;>
<br>
Last Name:
<Input type=&quot;Text&quot; Name=&quot;lname3&quot;>
<p>First Name:
<input type=&quot;TEXT&quot; Name=&quot;fname4&quot;>
<br>
Last Name:
<Input type=&quot;Text&quot; Name=&quot;lname4&quot;>
<p>
<p>First Name:
<input type=&quot;TEXT&quot; Name=&quot;fname5&quot;>
<br>
Last Name:
<Input type=&quot;Text&quot; Name=&quot;lname5&quot;>

<input type=&quot;SUBMIT&quot; VALUE=&quot;SUBMIT&quot;>

*********THIS IS THE INSERT/ACTION PAGE **************
THIS IS THE CODE FOR THE INSERT/ACTION PAGE:

<CFLOOP from=1 to=5 index=&quot;loopcount&quot;>
<CFSET currF=&quot;fname#loopcount#&quot;>
<CFSET currL=&quot;lname#loopcount#&quot;>
<Cfquery name=&quot;addjcode&quot; datasource=&quot;Timesheets&quot;>
INSERT testdata (Fname, Lname)
VALUES('#evaluate(currF)#', '#evaluate(currL)#')
</cfquery>
</CFLOOP>

** Thanks to WebMigit for this ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top