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!

how to create cfloop for insertion of data 1

Status
Not open for further replies.

Cher

Programmer
Jun 18, 2001
3
US
I've generated a cfloop to create textfields based on the user input from 1-5.(max up to 5 field)
<-- check to see if #form.input# GT 5-->
cfset count=#form.input#>
<cfif count GT 5>
<--Error message-->
<cfelse>
<cfloop index=&quot;index&quot; from=&quot;1&quot; to=&quot;#count#&quot;>
<cfoutput><input type=&quot;text&quot; size=&quot;5&quot; name=&quot;area&quot;>
</cfoutput></cfloop></cfif>
The problem I faced now is, how am I purpose to insert the data from the textfield into the database having that they have the same textfield name?Can this be done using loop?
 
Hi!

You should generetate dynamic name for your text field so that you have a different name for each field:

<-- check to see if #form.input# GT 5-->
cfset count = #form.input#>
<cfif count GT 5>
[tab]<--Error message-->
<cfelse>
[tab]<cfloop index=&quot;index&quot; from=&quot;1&quot; to=&quot;#count#&quot;>
[tab][tab]<cfoutput>
[tab][tab][tab]<input type=&quot;text&quot; size=&quot;5&quot; name=&quot;area#count#&quot;>
[tab][tab]</cfoutput>
[tab]</cfloop>
<-- dont forget to add an hidden field that will contain the number of file you had -->
<CFOUTPUT>
<INPUT TYPE=&quot;HIDDEN&quot; NAME=&quot;NumberOFTextField&quot; VALUE=&quot;#COUNT#&quot;>
<CFOUTPUT>

</cfif>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top