Insert Multiple Parts Problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bonneylake
    Contributor
    • Aug 2008
    • 769

    #31
    Originally posted by acoder
    Right, I see. Instead of serialcount, you'll want to use machinecount (the index variable of the first loop).
    Hey Acoder,

    So like this? does the index need to be removed or put a different name behind index?

    Code:
    <cfloop from="1" to="#form['partscount' & machinecount]#" index="machineCount">
    Thank you,
    Rach

    Comment

    • acoder
      Recognized Expert MVP
      • Nov 2006
      • 16032

      #32
      Yes, you should use a different name to avoid problems.

      Comment

      • bonneylake
        Contributor
        • Aug 2008
        • 769

        #33
        Originally posted by acoder
        Yes, you should use a different name to avoid problems.
        Hey Acoder,

        I did this

        Code:
        <!---Inserts parts information into parts table.--->
        <!---because it is a bit we don't use 'ticks' around defective for parts table--->
        <cfloop from="1" to="#form['partscount' & machinecount]#" index="ps">
        <cfquery name="parts" datasource="CustomerSupport">
            exec usp_CS_Insertparts
            <cfqueryparam value="#serialnum#" CFSQLType = "CF_SQL_VARCHAR">,
            '#Form.ID#',
            <cfqueryparam value="#hcpn#" CFSQLType = "CF_SQL_VARCHAR">,
            <cfqueryparam value="#partsreturn#" CFSQLType = "CF_SQL_VARCHAR">,
            <cfqueryparam value="#defective#" CFSQLType = "CF_SQL_BIT">,
           '#Form.submission#'
        </cfquery>
        </cfloop>
        but i am getting the following error

        An error occurred while evaluating the expression:


        hcpn = Form["hcpn_" & machineCount]


        Error near line 60, column 8.
        --------------------------------------------------------------------------------

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


        an the error comes from in the cfset area

        Code:
        <!---Inserts information into serial table.--->
        <CFIF REQUEST_METHOD EQ "POST">
        <CFSET machineListLen = listLen(Form.serialcount)>
        <CFLOOP from="1" to="#machineListLen#" index="machineCount">
         <CFSET serialnum       = Form["serialnum_" & machineCount]>
         <CFSET modelno         = Form["modelno_" & machineCount]>
         <CFSET producttype     = Form["producttype_" & machineCount]>
         <CFSET softhardware    = Form["softhardware_" & machineCount]>
         <CFSET resolution      = Form["resolution_" & machineCount]>
         <CFSET resdate         = Form["resdate_" & machineCount]>
         <CFSET resvertified    = Form["resvertified_" & machineCount]>
         <CFSET vertifidate     = Form["vertifidate_" & machineCount]>
         <CFSET deptvendor      = Form["deptvendor_" & machinecount]>
         <CFSET hardwarefailure = Form["hardwarefailure_" & machineCount]>
         <CFSET rma             = Form["rma_" & machineCount]>
         <CFSET thedescription  = Form["thedescription_" & machineCount]>
         <CFSET hcpn            = Form["hcpn_" & machineCount]>
         <CFSET partsreturn     = Form["partsreturn_" & machineCount]>
         <CFSET defective       = Form["defective_" & machineCount]>
        <!--- <CFSET followdate      = Form["followdate_" & machineCount]>
         <CFSET onsite          = Form["onsite_" & machineCount]>
         <CFSET numonsite       = Form["numonsite_" & machineCount]>--->
         
        <cfquery name="serial" datasource="CustomerSupport">
           exec usp_CS_Insertserial 
             <cfqueryparam value="#serialnum#" CFSQLType = "CF_SQL_VARCHAR">,
             '#Form.ID#',
             <cfqueryparam value="#modelno#" CFSQLType = "CF_SQL_VARCHAR">,
             <cfqueryparam value="#producttype#" CFSQLType = "CF_SQL_VARCHAR">,
             <cfqueryparam value="#softhardware#" CFSQLType = "CF_SQL_VARCHAR">,
             <cfqueryparam value="#resolution#" CFSQLType = "CF_SQL_VARCHAR">,
             <cfqueryparam value="#resdate#">,
             <cfqueryparam value="#resvertified#" CFSQLType = "CF_SQL_VARCHAR">,
             <cfqueryparam value="#vertifidate#">,
             <cfqueryparam value="#deptvendor#" CFSQLType = "CF_SQL_VARCHAR">,
             <cfqueryparam value="#hardwarefailure#" CFSQLType = "CF_SQL_VARCHAR">,
             <cfqueryparam value="#rma#" CFSQLType = "CF_SQL_VARCHAR">
           </cfquery>
           
        <!---Inserts information into notes_descr table.--->
        <cfquery name="description" datasource="CustomerSupport">
            exec usp_CS_Insertdescription
           <cfqueryparam value="#serialnum#" CFSQLType = "CF_SQL_VARCHAR">,
           '#Form.ID#',
           <cfqueryparam value="#thedescription#" CFSQLType = "CF_SQL_VARCHAR">,
           '#Form.fk_addedBy#'
        </cfquery>
        
        
        <!---Inserts parts information into parts table.--->
        <!---because it is a bit we don't use 'ticks' around defective for parts table--->
        <cfloop from="1" to="#form['partscount' & machinecount]#" index="ps">
        <cfquery name="parts" datasource="CustomerSupport">
            exec usp_CS_Insertparts
            <cfqueryparam value="#serialnum#" CFSQLType = "CF_SQL_VARCHAR">,
            '#Form.ID#',
            <cfqueryparam value="#hcpn#" CFSQLType = "CF_SQL_VARCHAR">,
            <cfqueryparam value="#partsreturn#" CFSQLType = "CF_SQL_VARCHAR">,
            <cfqueryparam value="#defective#" CFSQLType = "CF_SQL_BIT">,
           '#Form.submission#'
        </cfquery>
        </cfloop>
        </CFLOOP>
        </CFIF>
        Thank you,
        Rach

        Comment

        • acoder
          Recognized Expert MVP
          • Nov 2006
          • 16032

          #34
          The variables corresponding to the parts query should be in the second cfloop. Check what you've named the parts fields.

          Comment

          • bonneylake
            Contributor
            • Aug 2008
            • 769

            #35
            Originally posted by acoder
            The variables corresponding to the parts query should be in the second cfloop. Check what you've named the parts fields.
            Hey Acoder,

            i checked the fields an there named correctly unless instead of hcpn it needs to be hcpn_

            here is what i got in the javascript for it

            Code:
            "<table class='zpExpandedTable' id='resoltable' cellpadding='1' cellspacing='0' >" +
            "<th class='sectiontitle' colspan='7'>Parts Information "+ count +" Serial Information "+serialno+"</th>" +
            "<tr>" +
            "<td class='indent' id='formfieldpadding'>HC P/N:&nbsp;&nbsp;&nbsp;<input type='text' name='hcpn_" + count + "' style='margin:0px'></td>" +
            "<td class='red'>" +
            "Parts been returned* " +
            "<input type='checkbox' name='partsreturn_" + count +"' value='1'/>" +
            "</td>" +
            "<td>" +
            "<td class='indent'>Defective<input type='checkbox' name='defective_" + count +"' value='1'/></td>" +
            "</td>" +
            "</tr>" +
            "</table>" +
            and here is what i have for the submitting

            Code:
            <cfloop from="1" to="#form['partscount' & machinecount]#" index="ps">
             <CFSET hcpn            = Form["hcpn_" & machineCount]>
             <CFSET partsreturn     = Form["partsreturn_" & machineCount]>
             <CFSET defective       = Form["defective_" & machineCount]>
            <cfquery name="parts" datasource="CustomerSupport">
                exec usp_CS_Insertparts
                <cfqueryparam value="#serialnum#" CFSQLType = "CF_SQL_VARCHAR">,
                '#Form.ID#',
                <cfqueryparam value="#hcpn#" CFSQLType = "CF_SQL_VARCHAR">,
                <cfqueryparam value="#partsreturn#" CFSQLType = "CF_SQL_VARCHAR">,
                <cfqueryparam value="#defective#" CFSQLType = "CF_SQL_BIT">,
               '#Form.submission#'
            </cfquery>
            </cfloop>
            Thank you,
            Rach

            Comment

            • acoder
              Recognized Expert MVP
              • Nov 2006
              • 16032

              #36
              In that loop, for the parts query variables, you should replace machineCount with ps (the index variable).

              Comment

              • bonneylake
                Contributor
                • Aug 2008
                • 769

                #37
                Originally posted by acoder
                In that loop, for the parts query variables, you should replace machineCount with ps (the index variable).
                Hey Acoder,

                It worked, but didn't work. It inserted into the table but not how it needs to insert.
                When it inserted instead of creating a separate record for each part. It made 2 records but put the information from both parts in both records

                example

                here is how it looks

                record 1: hc_part no: test 1 p, test 2 p
                record 2: hc_part no: test 1 p, test 2 p

                an how it needs to look
                record 1: hc_part no: test 1 p
                record 2: hc_part no: test 2 p

                do i need to add this line to the top of parts?

                Code:
                <CFIF REQUEST_METHOD EQ "POST">
                here is what i have for parts

                Code:
                <cfloop from="1" to="#form['partscount' & machinecount]#" index="ps">
                 <CFSET hcpn            = Form["hcpn_" & ps]>
                 <CFSET partsreturn     = Form["partsreturn_" & ps]>
                 <CFSET defective       = Form["defective_" & ps]>
                <cfquery name="parts" datasource="CustomerSupport">
                    exec usp_CS_Insertparts
                    <cfqueryparam value="#serialnum#" CFSQLType = "CF_SQL_VARCHAR">,
                    '#Form.ID#',
                    <cfqueryparam value="#hcpn#" CFSQLType = "CF_SQL_VARCHAR">,
                    <cfqueryparam value="#partsreturn#" CFSQLType = "CF_SQL_VARCHAR">,
                    <cfqueryparam value="#defective#" CFSQLType = "CF_SQL_BIT">,
                   '#Form.submission#'
                </cfquery>
                </cfloop>
                Thank you :),
                Rach

                Comment

                • acoder
                  Recognized Expert MVP
                  • Nov 2006
                  • 16032

                  #38
                  Does this affect just hcpn or all three variables?

                  Comment

                  • bonneylake
                    Contributor
                    • Aug 2008
                    • 769

                    #39
                    Originally posted by acoder
                    Does this affect just hcpn or all three variables?
                    Hey Acoder,

                    It affects all 3 fields

                    Thank you,
                    Rach

                    Comment

                    • acoder
                      Recognized Expert MVP
                      • Nov 2006
                      • 16032

                      #40
                      Either check on the client-side (using, say, Firebug) what the generated source is when you have two parts, or turn debugging on and check what's passed through to Coldfusion. Check the names of the parts input fields.

                      You should turn debugging on anyway if you haven't already done so. On a development machine it should be turned on so you can get useful information about your application.

                      Comment

                      • bonneylake
                        Contributor
                        • Aug 2008
                        • 769

                        #41
                        Hey Acoder,

                        With the debugging for coldfusion i don't have the ability to turn it on because its controlled by the main web developer. Basically the errors i get are what i get.

                        but i opened up firebug an i didn't see anything that stands out. Basically here is what i get when i have to parts though.this is looking at the html of it.

                        dynamic1input
                        part1name1

                        dynamic2input
                        part1name2

                        an i noticed in the database that it puts the hcpn field like this part 1,part 2
                        however for all the other fields it only puts one value in those.

                        But here is what i have in full

                        Code:
                        <!---Inserts information into serial table.--->
                        <CFIF REQUEST_METHOD EQ "POST">
                        <CFSET machineListLen = listLen(Form.serialcount)>
                        <CFLOOP from="1" to="#machineListLen#" index="machineCount">
                         <CFSET serialnum       = Form["serialnum_" & machineCount]>
                         <CFSET modelno         = Form["modelno_" & machineCount]>
                         <CFSET producttype     = Form["producttype_" & machineCount]>
                         <CFSET softhardware    = Form["softhardware_" & machineCount]>
                         <CFSET resolution      = Form["resolution_" & machineCount]>
                         <CFSET resdate         = Form["resdate_" & machineCount]>
                         <CFSET resvertified    = Form["resvertified_" & machineCount]>
                         <CFSET vertifidate     = Form["vertifidate_" & machineCount]>
                         <CFSET deptvendor      = Form["deptvendor_" & machinecount]>
                         <CFSET hardwarefailure = Form["hardwarefailure_" & machineCount]>
                         <CFSET rma             = Form["rma_" & machineCount]>
                         <CFSET thedescription  = Form["thedescription_" & machineCount]>
                        <!--- <CFSET followdate      = Form["followdate_" & machineCount]>
                         <CFSET onsite          = Form["onsite_" & machineCount]>
                         <CFSET numonsite       = Form["numonsite_" & machineCount]>--->
                         
                        <cfquery name="serial" datasource="CustomerSupport">
                           exec usp_CS_Insertserial 
                             <cfqueryparam value="#serialnum#" CFSQLType = "CF_SQL_VARCHAR">,
                             '#Form.ID#',
                             <cfqueryparam value="#modelno#" CFSQLType = "CF_SQL_VARCHAR">,
                             <cfqueryparam value="#producttype#" CFSQLType = "CF_SQL_VARCHAR">,
                             <cfqueryparam value="#softhardware#" CFSQLType = "CF_SQL_VARCHAR">,
                             <cfqueryparam value="#resolution#" CFSQLType = "CF_SQL_VARCHAR">,
                             <cfqueryparam value="#resdate#">,
                             <cfqueryparam value="#resvertified#" CFSQLType = "CF_SQL_VARCHAR">,
                             <cfqueryparam value="#vertifidate#">,
                             <cfqueryparam value="#deptvendor#" CFSQLType = "CF_SQL_VARCHAR">,
                             <cfqueryparam value="#hardwarefailure#" CFSQLType = "CF_SQL_VARCHAR">,
                             <cfqueryparam value="#rma#" CFSQLType = "CF_SQL_VARCHAR">
                           </cfquery>
                           
                        <!---Inserts information into notes_descr table.--->
                        <cfquery name="description" datasource="CustomerSupport">
                            exec usp_CS_Insertdescription
                           <cfqueryparam value="#serialnum#" CFSQLType = "CF_SQL_VARCHAR">,
                           '#Form.ID#',
                           <cfqueryparam value="#thedescription#" CFSQLType = "CF_SQL_VARCHAR">,
                           '#Form.fk_addedBy#'
                        </cfquery>
                        
                        
                        <!---Inserts parts information into parts table.--->
                        <!---because it is a bit we don't use 'ticks' around defective for parts table--->
                        <cfloop from="1" to="#form['partscount' & machinecount]#" index="ps">
                         <CFSET hcpn            = Form["hcpn_" & ps]>
                         <CFSET partsreturn     = Form["partsreturn_" & ps]>
                         <CFSET defective       = Form["defective_" & ps]>
                        <cfquery name="parts" datasource="CustomerSupport">
                            exec usp_CS_Insertparts
                            <cfqueryparam value="#serialnum#" CFSQLType = "CF_SQL_VARCHAR">,
                            '#Form.ID#',
                            <cfqueryparam value="#hcpn#" CFSQLType = "CF_SQL_VARCHAR">,
                            <cfqueryparam value="#partsreturn#" CFSQLType = "CF_SQL_VARCHAR">,
                            <cfqueryparam value="#defective#" CFSQLType = "CF_SQL_BIT">,
                           '#Form.submission#'
                        </cfquery>
                        </cfloop>
                        </CFLOOP>
                        </CFIF>
                        Thank you,
                        Rach

                        Comment

                        • acoder
                          Recognized Expert MVP
                          • Nov 2006
                          • 16032

                          #42
                          Check the three variables in Firebug by expanding one part (the +) and see the values.

                          Is there no chance you could ask the main web developer to switch it on for you. Surely it'd make things easier.

                          Comment

                          • bonneylake
                            Contributor
                            • Aug 2008
                            • 769

                            #43
                            Originally posted by acoder
                            Check the three variables in Firebug by expanding one part (the +) and see the values.

                            Is there no chance you could ask the main web developer to switch it on for you. Surely it'd make things easier.
                            Hey Acoder,

                            Well with the main developer, i can never get a hold of him. We was suppose to go over something a week an a half ago an still haven't. But i did notice something looking for the 3 variables.

                            dynamic1input has this
                            Code:
                            <input id="partscount1" type="hidden" value="1" name="partscount1"/>
                            <input id="serialcount" type="hidden" value="1" name="serialcount"/>
                            dynamic2input

                            Code:
                            <input id="partscount2" type="hidden" value="1" name="partscount2"/>
                            <input id="serialcount" type="hidden" value="2" name="serialcount"/>
                            an when i looked under part1Name1 and part1Name2 all the fields had hcpn_1 partsreturn_1 and defective_1. I don't know if that means anything but thought i would point it out.

                            Thank you,
                            Rach

                            Comment

                            • acoder
                              Recognized Expert MVP
                              • Nov 2006
                              • 16032

                              #44
                              That will be the problem. All parts variables have the same name, so when passed to Coldfusion, it's passed as a list which is what's being added to the database.

                              What you'll need to do is make all parts fields unique. You can do that by adding the serial count to the name, e.g. by adding "_" + serialcount, then modifying the Coldfusion to get each unique parts field.

                              Comment

                              • bonneylake
                                Contributor
                                • Aug 2008
                                • 769

                                #45
                                Originally posted by acoder
                                That will be the problem. All parts variables have the same name, so when passed to Coldfusion, it's passed as a list which is what's being added to the database.

                                What you'll need to do is make all parts fields unique. You can do that by adding the serial count to the name, e.g. by adding "_" + serialcount, then modifying the Coldfusion to get each unique parts field.
                                Hey Acoder,

                                I get what your saying, just not sure on the naming part. So would something like this work?

                                Code:
                                <input type='text' name='hcpn_" + count + "_"+serialcount"' style='margin:0px'>
                                Thank you,
                                Rach

                                Comment

                                Working...