Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Add multiple product id and quantity to database with 1 form

New Here ,
Sep 12, 2011 Sep 12, 2011

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

TOPICS
Advanced techniques
377
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 12, 2011 Sep 12, 2011
LATEST

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>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources