I was able to figure out how to do the multi insert.  Here are the steps I took.

To make sure the form values where passed I setup an actionpage.cfm instead of 
going directly to a cfc.  On the top of the page I added <cfdump var="#form#" 
label="Form variables" />.

Once I knew extactly what formfields where passed I created a variable to hold 
the number of mulitple fields for insert.

<cfset formCount = ListLen('#FORM.FieldNames#', ",")>

<!--- minus hidden and other fields that are not part of the multi insert -->
        <cfset formCount = formCount - 4>

<!--- Query to insert into the fist table.  These values are not part of the 
multi insert. --->

 <cftransaction>
        <cfquery datasource="#request.dsn#">
                INSERT INTO cart (cart_custcart_ID, productID, qty, 
cart_dateadded)
                VALUES ('#Client.CartID#',#FORM.productid# ,#FORM.qty# 
,#CreateODBCDateTime(Now())#)
        </cfquery>

<!--- Get the last id for use in the multi insert --->
                
        <cfquery name="lastRec" datasource="#request.dsn#">
                SELECT LAST_INSERT_ID() as lastid
        </cfquery>
                        
<!--- I set the lastID cause without it I get an error message ---> 
        <cfset lastID = lastRec.lastid>

<!--- Here is where the multi insert is done. The formCount is used to setup 
loop for the Options --->
                        
        <cfloop from="1" to="#formCount#" index="i">
                <cfquery datasource="#request.dsn#">
                 INSERT cart_options (optionID, cartLineID)
                 VALUES ('#Evaluate("form.option#i#")#', #LastID#)
                </cfquery>
        </cfloop>
 </cftransaction>

I still have a problem I hope someone can answer.  On the form if their are 3 
options to select from (radio buttons) and I select option 1 and 3, I get an 
error message because the options are not concurrent .  This is because the 
loop goes thru 2 options; option1 and option2 instead of option1 and option3 
and gives an error stating their is no value for option2.  Any ideas?

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Message: http://www.houseoffusion.com/lists.cfm/link=i:4:231710
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

Reply via email to