Cfform variable values ​​- pound sign

I have a problem with a problem. I use cfoutput to run query results inside a form. There are several cfselects that are dynamically called, i.e. entry_1, entry_2, etc. Then they are passed to the algge actionpage with the number of entries in the url where I want to insert them into the cfloop database.

<cfloop from="1" to="#url.Count#" index="i"> <cfquery name="id_#i#" datasource="xxx">Insert Into table1(entry_level) Values(#form.entry_#i##)</cfquery> </cfloop> 

And every time he throws a mistake. I tried using an array format, but I still can't get it to work. Please, help!

+4
source share
1 answer

You cannot create a dynamic structure selector this way. You can do something like the following to get the same result.

So, using the following data:

 <cfset url.count = 3> <cfset form.entry_1 = 1> <cfset form.entry_2 = 2> <cfset form.entry_3 = 3> 

Something like this will work -

 <cfloop from="1" to="#url.Count#" index="i"> <cfquery name="id_#i#" datasource="xxx"> Insert Into table1(entry_level) Values(#form['entry_' & i]#) </cfquery> </cfloop> 

ColdFusion basically provides you with two ways to access the value of a structure, either through a. designation or through brackets. If you are trying to access the structure using a dynamic key, you need to use parentheses.

By the way, a little better would be:

  <cfloop from="1" to="#url.Count#" index="i"> <cfquery name="id_#i#" datasource="xxx"> Insert Into table1(entry_level) Values(<cfqueryparam value="#form['entry_' & i]#">) </cfquery> </cfloop> 

cfQueryParam automatically escapes writing, so you don’t have to worry about SQL injection attacks. It can also make the request a little more efficient.

+10
source

All Articles