15 Replies Latest reply on Oct 10, 2007 10:46 AM by cf_dev2

    Looping through form

    still_smiling
      I have a page, http://www.boey.com/hms/vbc/vbc_edit_po.cfm?PO=333 that I need to save the data per "line_id" on the next page. However, when I loop through the "Line_id" it puts the data from the form fields, "W/S" like this... 45,50 so I tried looping through both "Line_id" and "w/s" and it doesn't work. How can I can update my table from this form? There are two different tries in my attached code.

      Thanks,
      Courtney
        • 1. Re: Looping through form
          suchil00
          I had a very similar situation and this tutorial helped me. Try it.
          http://tutorial214.easycfm.com/
          • 2. Re: Looping through form
            still_smiling Level 1
            I've worked through the tutorial and I'm stuck with a problem still. Please take a look at the following code:

            Website page can be located at http://www.boey.com/hms/vbc/vbc_edit_po.cfm?PO=333

            • 3. Re: Looping through form
              suchil00 Level 1
              First thing you'll notice that in the tutorial - there are 2 lines for each variable. That is just the way it work when using Evaluate. However, from reading these forums, I gather 'Evaluate' is not the best function to use. So here's a method to achive the same in a single line.

              Your first variable would look like the attached code. Do this for all your variables and it should work.


              • 4. Re: Looping through form
                cf_dev2 Level 1
                > <cfset variables.Line_ID = #Form["Line_ID" & LoopCount]#>

                .. but lose the the # signs. They're not needed.

                <cfset variables.Line_ID = Form["Line_ID" & LoopCount]>
                • 5. Re: Looping through form
                  still_smiling Level 1
                  Neither of those suggestions are working. I tried various things with those two statements and I'm still getting an error which is below. What is weird is that it reads this from the previous page..

                  <input type="Text" name="LineID#GetInfo.CurrentRow#" value="#GetInfo.Line_id#">

                  Since the code you provided is still not working maybe I have this statement incorrect. Getting frustrated.

                  ------------------------------------------------------------------------------------------ ---------------------------------

                  Error Occurred While Processing Request

                  Error Diagnostic Information

                  An error occurred while evaluating the expression:

                  variables.Line_ID = Form["Line_ID" & LoopCount]

                  Error near line 4, column 10.

                  The member "LINE_ID1" in dimension 1 of object "Form" cannot be found. Please, modify the member name.

                  The error occurred while processing an element with a general identifier of (CFSET), occupying document position (4:4) to (4:58).

                  Date/Time: 10/10/07 10:53:28
                  Browser: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.7) Gecko/20070914 Firefox/2.0.0.7
                  Remote Address: 76.6.58.23
                  HTTP Referrer: http://www.boey.com/hms/vbc/vbc_edit_po.cfm?PO=333
                  Query String: ID=

                  Please inform the site administrator that this error has occurred (be sure to include the contents of this page in your message to the administrator).
                  • 6. Re: Looping through form
                    cf_dev2 Level 1
                    > <input type="Text" name="LineID#GetInfo.CurrentRow#" value="#GetInfo.Line_id#">

                    Your form field names don't match. The input field name starts with LineID but you're using Line_ID

                    Try instead
                    <cfset variables.Line_ID = Form["LineID" & LoopCount]>
                    • 7. Re: Looping through form
                      still_smiling Level 1
                      Now that seems to be working but I'm still getting an error...


                      Error Occurred While Processing Request

                      Error Diagnostic Information

                      ODBC Error Code = 07001 (Wrong number of parameters)

                      [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 8.

                      Hint: The cause of this error is usually that your query contains a reference to a field which does not exist. You should verify that the fields included in your query exist and that you have specified their names correctly.

                      The error occurred while processing an element with a general identifier of (CFQUERY), occupying document position (10:4) to (10:51).

                      Date/Time: 10/10/07 11:22:17
                      Browser: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.7) Gecko/20070914 Firefox/2.0.0.7
                      Remote Address: 76.6.58.23
                      HTTP Referrer: http://www.boey.com/hms/vbc/vbc_edit_po.cfm?PO=333
                      Query String: ID=
                      • 8. Re: Looping through form
                        cf_dev2 Level 1
                        Is that error from the update query, because the UPDATE seems to use only 7 fields?

                        1. Are the table column names are correct
                        2. Check the data types of the columns against the cfsqltypes. Are they correct?
                        You're using cf_sql_varchar for the "del_ Date" column. Is del_Date really a 'text' column?

                        3. You're using null="yes" for all of the parameters. That seems wrong because it will update the columns with NULL and ignore the form values.



                        • 9. Re: Looping through form
                          cf_dev2 Level 1
                          Does the query actually work without the cfqueryparam's?

                          This isn't tested, so there may be typos.

                          <cfquery name="UpdateInfo" datasource="fabrics">
                          UPDATE tbl_orders
                          SET W_S = '#variables.w_s#',
                          del_Date = '#variables.del_Date#',
                          pieces = '#variables.pieces#',
                          piece_length = '#variables.piece_length#',
                          other_pieces = '#variables.other_pieces#',
                          po_comments = '#variables.po_comments#'
                          WHERE Line_ID = #variables.Line_ID#
                          </cfquery>
                          • 10. Re: Looping through form
                            still_smiling Level 1
                            I got it to work just fine. I'm working out some other details that have to with other items on that form. May have more questions at some point.
                            Thanks
                            • 11. Re: Looping through form
                              cf_dev2 Level 1
                              Glad you got it working.

                              Hopefully you figured out how to do it with <cfqueryparam>. It has some extra benefits when used inside a cfloop, due to the usage of bind variables.
                              • 12. Re: Looping through form
                                still_smiling Level 1
                                I did. I've attached the code in case someone else is looking to do the same thing.


                                • 13. Re: Looping through form
                                  cf_dev2 Level 1
                                  I assume you accidentally left out the WHERE clause in the second update. Otherwise, you'd be updating all records in tbl_comments every time.
                                  • 14. Re: Looping through form
                                    still_smiling Level 1
                                    Yes. That piece is still being worked out. Should have left it out.
                                    • 15. Re: Looping through form
                                      cf_dev2 Level 1
                                      Okay. Good luck with the rest of your form :)