Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CFLOOP and insert query

Status
Not open for further replies.

cdw0308

Technical User
Oct 8, 2003
181
US
I am trying to use an insert query in my cfloops.
I started out with this code that displays the values to the page. It works just fine. Now I wanted to modify it to include an insert query that sent the data to a database

Code:
<cfset j = #total_count#>
<cfloop index = "RowCount" from = "1" to = #j#>
   <cfloop index="ColumnCount" from = "1" to = "3">       
           <cfoutput>#Evaluate("txt" & ColumnCount & "Row" & RowCount)#</cfoutput>&nbsp;&nbsp;
    </cfloop><br><br>
   <cfset j = j + 1>
</cfloop>
So i tried putting an insert query in and it does not work.

Code:
<cfset j = #total_count#>
<cfloop index = "RowCount" from = "1" to = #j#>
   <cfloop index="ColumnCount" from = "1" to = "3">
           <cfquery name="add_asset" datasource="#conn#">
            INSERT INTO asset (item_num, manuf, model_num) 
            VALUES('#item_num#', '#manuf#', '#model_num#')
            </cfquery> 
           
               <cfoutput>#Evaluate("txt" & ColumnCount & "Row" & RowCount)#</cfoutput>&nbsp;&nbsp;
    </cfloop><br><br>
   <cfset j = j + 1>
</cfloop>
When I enter 3 rows of data on my form i wanted it inserted into the table in 3 differant rows.
Any help would be greatly appreciated.
 
Work it out... whats the error? Where in the code does the error occur? where are item_num, manuf, and model_num coming from?

what does your form look like, can we see it? I can't figure out what your loops are actualy for if this is from form data.

can you post your form code and all of the processing code for the form?


Kevin

Phase 1: Read the CFML Reference
Phase 2: ???
Phase 3: Profit!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top