Skip to main content
Participant
September 12, 2011
Question

Add multiple product id and quantity to database with 1 form

  • September 12, 2011
  • 1 reply
  • 397 views

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

This topic has been closed for replies.

1 reply

bbdgAuthor
Participant
September 12, 2011

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>