Solved

CFLOOP and Insert

Posted on 2008-06-23
3
431 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
  • 2
3 Comments
 
LVL 14

Expert Comment

by:SBennett
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:
SBennett 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

A web service (http://en.wikipedia.org/wiki/Web_service) is a software related technology that facilitates machine-to-machine interaction over a network. This article helps beginners in creating and consuming a web service using the ColdFusion Ma…
When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

762 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now