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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Looping through form items 1

Status
Not open for further replies.

bobbyr

Programmer
Nov 30, 2000
66
0
0
US
I'm having a problem looping through my form items and inserting the data. My code looks something like this:

<form action=&quot;action.cfm&quot; method=&quot;post&quot;>
<input type=&quot;text&quot; name=&quot;Name1&quot; value=&quot;Jimmy&quot;>
<input type=&quot;text&quot; name=&quot;Number1&quot; value=&quot;33&quot;>
<input type=&quot;text&quot; name=&quot;Name2&quot; value=&quot;Fred&quot;>
<input type=&quot;text&quot; name=&quot;Number2&quot; value=&quot;43&quot;>
<input type=&quot;text&quot; name=&quot;Name3&quot; value=&quot;Amy&quot;>
<input type=&quot;text&quot; name=&quot;Number3&quot; value=&quot;65&quot;>
<input type=&quot;text&quot; name=&quot;Name4&quot; value=&quot;Dan&quot;>
<input type=&quot;text&quot; name=&quot;Number4&quot; value=&quot;76&quot;>
</form>

My action page needs to loop through the items and enter each form item into the database fields &quot;Name&quot; and &quot;Number&quot;. Any help?
 
<cfloop index=&quot;i&quot; from=&quot;1&quot; to=&quot;4&quot; step=&quot;1&quot;>
<cfset tempName = evaluate(&quot;form.Name#i#&quot;)>
<cfset tempNumber = evaluate(&quot;form.Number#i#&quot;)>
<cfquery name=&quot;InsertItem&quot; datasource=&quot;#application.dsn#&quot; username=&quot;#application.dsnusername#&quot; password=&quot;#application.dsnPassword#&quot;>
Insert into TableName (Name,Number)
values ('#tempName#', '#tempNumber#')
</cfquery>
</cfloop>

That should do it. :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top