Solved

CFLOOP and Insert

Posted on 2008-06-23
3
437 Views
Last Modified: 2013-12-24
I have the following URL which I am parsing out the information from.

http://site.com/verifyids2.cfm?CNO=12345&id1=001&id2=002&id3=003&sn1=alastl&sn2=bflast2&sn3=clast3

I check to see if the values are valid and if not I need to insert a new record into the database. Each record needs to be insert separately. For example, the first record would insert the CNO, id1, sn1. If exists the second record would insert the s same CNO but then id2, sn2 and so on.
I have all the variables defined but I am having trouble with the loop and insert.

<cfset ids="#id1#,#id2#,#id3#" />
<cfset sns="#sn1#,#sn2#,#sn3#" />
<cfset qArray = listToArray(ids) />
<cfset aArray = listToArray(sns) />

<cfloop list="qArray" item="i">
           
     <cfquery name="AddUser" datasource="helengrace">
          INSERT INTO dbo.ib_ChildReg
(custno,IID,samplename1)
          VALUES ( '#cno#',
                                '#qArray[i]#',
                                '#aArray[i][1]#',
                                '#aArray[i][2]#',
                                '#aArray[i][3]#',);
     </cfquery>
</cfloop>
0
Comment
Question by:usky1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 14

Expert Comment

by:Scott Bennett
ID: 21868247
Your loop syntax is wrong, try it like this:
<cfloop from="1" to="#arraylen(qArray)#" index="i">
     <cfquery name="AddUser" datasource="helengrace">
          INSERT INTO dbo.ib_ChildReg (custno,IID,samplename1)
          VALUES ( '#cno#',
                                '#qArray[i]#',
                                '#aArray[i][1]#',
                                '#aArray[i][2]#',
                                '#aArray[i][3]#',);
     </cfquery>
</cfloop>

Open in new window

0
 
LVL 14

Accepted Solution

by:
Scott Bennett earned 500 total points
ID: 21868263
You query syntax is wrong as well.. use this instead:
<cfloop from="1" to="#arraylen(qArray)#" index="i">
     <cfquery name="AddUser" datasource="helengrace">
          INSERT INTO dbo.ib_ChildReg (custno,IID,samplename1)
          VALUES ( '#cno#',
                                '#qArray[i]#',
                                '#aArray[i]#');
     </cfquery>
</cfloop>

Open in new window

0
 

Author Closing Comment

by:usky1
ID: 31469893
Sorry it took awhile to get back. Thanks for your help.
0

Featured Post

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: kevp75
Hey folks, 'bout time for me to come around with a little tip. Thanks to IIS 7.5 Extensions and Microsoft (well... really Windows 8, and IIS 8 I guess...), we can now prime our Application Pools, when IIS starts. Now, though it would be nice t…
What You Need to Know when Searching for a Webhost Provider
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question