Solved

double insertion using cfquery

Posted on 2004-09-10
4
463 Views
Last Modified: 2013-12-24
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
0
Comment
Question by:MMsabry
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 17

Expert Comment

by:Tacobell777
ID: 12031048
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
 

Author Comment

by:MMsabry
ID: 12031148
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
 
LVL 2

Accepted Solution

by:
Lunchy earned 0 total points
ID: 12148823
Closed, 500 points refunded.
Lunchy
Friendly Neighbourhood Community Support Admin
0

Featured Post

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Lease-to-own eliminates the expenditure of hardware replacement and allows you to pay off the server over time. Usually, this is much cheaper than leasing servers. Think of lease-to-own as credit without interest.
What You Need to Know when Searching for a Webhost Provider
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question