Solved

CFLOOP and Insert

Posted on 2008-06-23
3
436 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: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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

In our day to day coding, how many times have we come across a necessity to check whether a URL is a broken link or not? For those of you that answered countless and are using ColdFusion like myself, then this article is for you.  It will show yo…
Periodically we have to update or add SSL certificates for customers. Depending upon your hosting plan you may be responsible for the installation and/or key generation. In the wake of Heartbleed many sites were forced to re-key. We will concen…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

839 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