Skip navigation
Currently Being Moderated

How do i transfer funds from one account to another in the same table?

Feb 23, 2014 6:13 PM

24-02-2014 01-54-39.jpg

Say for example i want to transfer funds from UserID 1111101 to UserID  1111103.


Anyone know the procedure for this. I use php/mysql and dreamweaver.

  • Currently Being Moderated
    Feb 23, 2014 7:30 PM   in reply to gurroby

    In a basic accounting scenario, you first insert a transaction in a transaction table. That table contains the amount of the transaction, as well as the credit and debit accounts. You then update the balance of each account using two update statements. All of these operations need to be atomic - that is -they all must succeed or else be rolled back. So you need to incorporate transaction management.

    Mark as:
  • Currently Being Moderated
    Feb 24, 2014 9:52 AM   in reply to gurroby

    Here's a very basic method. Note that this is just pseudocode - you'll need to work out the actual code (I assume you've learned how in your course studies). Keep in mind this is a very simplified workflow - a real bank transaction would be MUCH more complex.


    Create a form that has fields for debit account, credit account, amount


    In your script, assign the values from the form to local variables





    I'll assume you have an account balance table 'acct_bal'. Have a journal table to store those values along with the date and autonumber transaction id.


    Begin Trans

    INSERT into journal (credit_acct, debit_acct, amount, trans_date) VALUES ($credit_acct, $debit_acct, $amount, NOW())

    Get the transaction_id ($trans_id) from the INSERT statement- the method depends on which MySQL interface you are using.

    UPDATE acct_bal SET balance = (balance + $amount) WHERE acct_id = $debit_acct

    UPDATE acct_bal SET balance = (balance - $amount) WHERE acct_id = $credit_acct


    Rollback on any SQL error else Commit Trans.

    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points