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

Dynamic variable inside cfloop

Explorer ,
Nov 13, 2008 Nov 13, 2008

Copy link to clipboard

Copied

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

Views

382

Translate

Translate

Report

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!

Votes

Translate

Translate
Valorous Hero ,
Nov 13, 2008 Nov 13, 2008

Copy link to clipboard

Copied

> 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.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

LATEST
Thank you.
Sorted!

Votes

Translate

Translate

Report

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
Documentation