?
Solved

CFLOOP and Insert

Posted on 2008-06-23
3
Medium Priority
?
440 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 2000 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

Get MySQL database support online, now!

At Percona’s web store you can order your MySQL database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card.

Question has a verified solution.

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

Lease-to-own eliminates the expenditure of hardware replacement and allows you to pay off the server over time. Usually, this is much cheaper than leasing servers. Think of lease-to-own as credit without interest.
What You Need to Know when Searching for a Webhost Provider
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

777 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