Solved

preventing update of customer balance twice

Posted on 2012-03-18
6
229 Views
Last Modified: 2012-06-21
I have a web application using coldfusion and mysql. There is a form where
customer's payment is entered and submitted. Upon submission customer's
balance is updated. Sometimes customer's balance is updated twice.
How do I prevent this from happening?  

Example:
Balance:  1000
payment: 100
After update: balance = 800
 
Thanks.
0
Comment
Question by:SonnyRey
  • 3
  • 3
6 Comments
 
LVL 24

Expert Comment

by:johanntagle
ID: 37734749
Without seeing your code, it's hard to make specific suggestions.  But one solution is to generate a unique identifier, something like a transaction or order id.  When the user clicks submit, the application should check if payment has already been made for this id.  If so, then it has found a duplicate payment.
0
 

Author Comment

by:SonnyRey
ID: 37734934
how do you make a unique id?  Cannot make a unique id based on time.
0
 
LVL 24

Expert Comment

by:johanntagle
ID: 37735484
You can just use an integer primary key column + auto_increment
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

Author Comment

by:SonnyRey
ID: 37736462
This is my code for updating the balance.

<cfquery name="updBal" datasource="#dsn#">
       update cust
       balance = balance - #form.payment#
</cfquery>

<cfquery name="addToTransact datasource="#dsn#">
     insert into transact
     (name, payment, pay_date)
     values
     ('#form.name#', '#form.payment#', #Now()#)
</cfquery>

Transact table and cust table have primary id (transactid and custid)

Sometimes this piece of code is executed twice.  When that happens transactid
is incremented twice for the two records inserted.

How would a primary key come into play?

Thanks.
0
 
LVL 24

Accepted Solution

by:
johanntagle earned 500 total points
ID: 37736491
transactid is the primary key for transact, and yet the insert statement above does not include that column, so I assume that has integer auto_increment in your definition.  I think what you need to do is to already insert a row to the transact table before processing payment (so payment column is currently null), note the generated transactid, then make it part of the form, maybe as a hidden field.

Then when the form is submitted, a check is made if the row with that transactid already has a value for payment.  If so, then it is considered a duplicate and nothing else happens.  If not, then the usual balance update should proceed.
0
 

Author Comment

by:SonnyRey
ID: 37736918
That might work. Let me try it.
Thanks.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

A lot of articles have been written on splitting mysqldump and grabbing the required tables. A long while back, when Shlomi (http://code.openark.org/blog/mysql/on-restoring-a-single-table-from-mysqldump) had suggested a “sed” way, I actually shell …
This guide whil teach how to setup live replication (database mirroring) on 2 servers for backup or other purposes. In our example situation we have this network schema (see atachment). We need to replicate EVERY executed SQL query on server 1 to…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

707 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

19 Experts available now in Live!

Get 1:1 Help Now