double insertion using cfquery

So i have a number of queries running on different pages,
on the final page, where the totals are entered and the payment status are also entered, and an invoice number is generated.
every thing goes fine until the last query, i get a douple insert, one with the P_ID entered and the rest is empty except for the invoce number (which is automatically generated)
the second insert, the P_ID is empty but the rest is entered. you have to notice that only one user at a time is entered per session, so the info in the arrays and the structures belong to one user, so i guess no need to loop over it?
here is the code
<cflock scope="session" type="exclusive" timeout="10" throwontimeout="no">
            <cfset Pay = Duplicate(Session.PartAct.Pay)>
            <cfset Pinfo = Duplicate(Session.PartAct.Pinfo)>
            <cfset Total = Duplicate(session.PartAct.Sum)>
      </cflock>
      <cftransaction action="begin">
            <cftry>
                  <cfquery name="inputtotal" datasource="#request.MyDSN#">
                  INSERT INTO dbo.Status (P_ID,total,regsub,accosub,socisub)
                  VALUES (#Pinfo[5]#, #Total[4]#, #Total[1]#, #Total[2]#, #Total[3]#);
                  
                </cfquery>
            
          <cfcatch type="any">
               <cftransaction action="rollback" />
         </cfcatch>
      </cftry>
      <cftransaction action="commit" />
</cftransaction>

I have tried this without the <cftransaction action="commit" />, and with a starting <cftransaction action="begin">
I have also removed the table from the db and remade it.
here is how the table looks like after the insertion
------------------------------------------------------------|
|P_ID|Total|regsub|accosub|socisub|Invoicenumber|
|-----------------------------------------------------------|
|1     |null  | null    | null     | null     |2                  |
------------------------------------------------------------|
|null  |200 |100     | 50       | 50      | 3                 |
------------------------------------------------------------|

I know you will tell me that i'm better off without storing these values in the table since i can calculate them on the fly, but at the moment i'm short on time, and since i'm new to all of this, i will do it this way for now then later modifiy it.

but i need a solution to this double insertion thing, especially that it does not add all the values twice, it actually pick on them
MMsabryAsked:
Who is Participating?
 
LunchyConnect With a Mentor Commented:
Closed, 500 points refunded.
Lunchy
Friendly Neighbourhood Community Support Admin
0
 
Tacobell777Commented:
Can't tell you why two records are inserted, you will have to show all of the code.
I can tell you that what I see looks a bit weird.

I think you are inserting each index of an array?
Total[4]#, #Total[1]#, #Total[2]#, #Total[3] is that correct?

you could just do arraySum(session.PartAct.Sum) to get the total of the array
0
 
MMsabryAuthor Commented:
ok, Tacobell777
I cannot do that, since i need to insert every subtotal at the moment, until i figure out how to use the stored procedure (which i have to learn) but since i do not have time at the moment, i will have to store all the values.

I figured out what was going wrong, a couple of pages before that, i had already inserted a value into the table, the pid and another value. and that is why i was always seeing two columns with the same pid, one is full without the other value, and the second row only contains the insertion from the first query. so i just had to use update statment and not insert.
thanks for your help any way.
sabry
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.