1 Reply Latest reply on Sep 12, 2011 10:26 AM by bbdg

    Add multiple product id and quantity to database with 1 form

    bbdg

      I have been programming coldfusion for a while, but this is the first time ive ever needed to add multiple products to a database with 1 submit button.  Strange, I know, but I dont want to spend days trying to come up with something when I know there are smarter people out there who probably know a very good way to do this.  So here it is:

       

      • Products pulled from database and a hidden field with the "itemid" as well as a "quantity" field is generated in a cfoutput
      • want to submit and whatever rows have a quantity entered, will be submitted to the database (itemid,quantity)

       

      Here is a screenshot

      Screen Shot 2011-09-12 at 12.54.59 PM.png

        • 1. Re: Add multiple product id and quantity to database with 1 form
          bbdg Level 1

          I figured it out.  You add a #currentrow# on each of the form items.  Then loop through and set up each row before inserting

           

          <cfloop from="1" to="#form.numberOfRows#" index="i">

            <cfif form['quantity' & #i#] NEQ ''>

           

                <cfset form.quantity="#form['quantity' & i]#">

                <cfset form.itemId="#form['itemid' & i]#">

                <cfset form.pricesold="#form['itemprice' & i]#">

           

               <cfinsert datasource="#application.dsn#" tablename="cart">

             

            </cfif>

            </cfloop>