Skip to main content
Participant
July 3, 2007
Answered

Combining Variables

  • July 3, 2007
  • 3 replies
  • 410 views
I have a form that is being generated via a query loop. One of the fields is 'ispercentage'&i (which the i is the index for the loop). So the number afterwards could be between 0 and 9. So obviously the variable name is going to change. How do I place that into my sql insert query? I can't do #form.ispercentage# because that comes back undefined (as is would be 'ispercentage(1-9 or even more as more are added)'. The sql insert query is also looping to add each new item.

This topic has been closed for replies.
Correct answer Newsgroup_User
The generally preferred method is array notation:
#form['scheduleuser" & i]#

3 replies

Inspiring
July 4, 2007
> Actually, no! I knew there was something wrong there, but you pointed it out! That line actually shouldn't even be there! It works perfect now! Thanks so much for the help!

The best way of troubleshooting this sort of thing is to use your eyes. As
part of the error message, it will display the actual SQL statement that
was trying to be executed. This is usually the best thing to check for
syntax errors like this, rather than looking at the code that generates the
SQL, which relies on you executing the code in your head, as well as having
to sort out what is CF code and what is SQL and what is... missing.

--
Adam
Participant
July 3, 2007
Actually, no! I knew there was something wrong there, but you pointed it out! That line actually shouldn't even be there! It works perfect now! Thanks so much for the help!
Newsgroup_UserCorrect answer
Inspiring
July 3, 2007
The generally preferred method is array notation:
#form['scheduleuser" & i]#

Participant
July 3, 2007
That works great! One more problem...it's syntax. Does anyone see the problem here?

<cfquery datasource="#application.dsn#">
INSERT INTO commSchedules(commScheduleName, brokerageID, <cfif IsDefined (#form['ispercentage' & i]#)>1<cfelse>0</cfif>userID, percentage, percofpie)
VALUES (#schName#, #form.brokerage#, #form['ispercentage' & i]#, #form['scheduleuser' & i]#, #form['totalperc' & i]#, #form['amount' & i]#)
</cfquery>

I get this error:
Error Executing Database Query.
[Macromedia][SQLServer JDBC Driver][SQLServer]Incorrect syntax near '0'.