Solved

double insertion using cfquery

Posted on 2004-09-10
4
458 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
4 Comments
 
LVL 17

Expert Comment

by:Tacobell777
Comment Utility
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
Comment Utility
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
Comment Utility
Closed, 500 points refunded.
Lunchy
Friendly Neighbourhood Community Support Admin
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

This is a guide to setting up a new WHM/cPanel Server to be used for web hosting accounts. It is intended for web hosting company administrators and dedicated server owners. For under $99 per month (considering normal rate of Big Data Cetnters like …
Periodically we have to update or add SSL certificates for customers. Depending upon your hosting plan you may be responsible for the installation and/or key generation. In the wake of Heartbleed many sites were forced to re-key. We will concen…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

772 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now