Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Dynamic variable inside cfloop

Explorer ,
Nov 13, 2008 Nov 13, 2008
Good day

I have a dynamic form which looks something like this...
<Cfloop from 1 to 6 indes i>
<cfinput type="text" name="description#i#" class="TextBlock">
</cfloop>

When submitting, I want to insert description#i# into a db

At the moment i have this...
<Cfset thedescription = description#i#">
<cfquery name="insertpic" datasource="#application.db#">
INSERT INTO tblpics
(description,)
VALUES ('#thedescription#')
</cfquery>

Its all inisde a loop

How do i set description#i# = somevar?

Please can someone assist?

Regards
Delon
TOPICS
Advanced techniques
400
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Explorer , Nov 14, 2008 Nov 14, 2008
Thank you.
Sorted!
Translate
Valorous Hero ,
Nov 13, 2008 Nov 13, 2008
> How do i set description#i# = somevar?

If you are using method="post", form field values are available in the FORM structure. For method="get" they are available in the URL structure. Since they are structures, you can use array notation to extract reference the dynamic field names: #FORM["baseFieldName"& counterVariable]#

<cfloop index="i" ...>
<cfset description = FORM["description"& i]>
...
</cfloop>

Also, consider using cfqueryparam for all query parameters. Especially when looping.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 14, 2008 Nov 14, 2008
LATEST
Thank you.
Sorted!
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources