WebReference.com logo
tip archive  •   about  •   sitemap  •   contact  •   jobs  •   write for us  •   subscribe


[next]

Creating a Banking Application Deposit Script

By

Social Bookmark

JAVA Developer – Trading Industry (NYC)
Next Step Systems
US-NY-New York

Justtechjobs.com Post A Job | Post A Resume


In the last article, we looked at the withdraw script that enables a customer to make a withdrawal from an account of their choice. In this article, we explore the mechanisms behind how to make a deposit into an account. We also look at the code that makes up the two methods that we briefly discussed in the previous article.

A method or two...

The two methods that we want to look at are the:

Below is the code for both the methods:

The currbalance() method is responsible for getting the current balance of the account, based on the account number that is fed into it. It starts by checking if a database connection is active or set:

Next, we build the SQL query that will be required to extract the data that we need:

Since it is a SELECT query we need to run it, the code does exactly that:

Now we test to see if any results have been returned. The results of the query are stored in the $res variable:

Note that an exception is created if an error occurs. If no errors were encountered during execution, we store the retrieved account balance in a variable called $row:

The current balance of the account is then stored in a variable called $currbal and returned to the function:

The setbalance() method is responsible for updating the balance of an account. Below is the code for the method:

It starts off by checking to see if a database connection is active or set:

Then we build an SQL query that will update or set the new balance:

We run the query and throw an exception if the query runs into any problems:

Unlike the currbalance() method, this method returns true or false. True if the query was successful and false if the query was unsuccessful:

The deposit.php script

The main purpose of this script is to provide the user with an opportunity to make a deposit to the preferred account. As you know by now, the homepage lists all the accounts of a particular user and provides two options; one of the options is to make a deposit. Below is screenshot of the page followed by the code that makes up this script:

Figure 1

The code

The code for the deposit.php script and the withdraw.php script is not so different. Both scripts make use of the setbalance and currbalance() methods. The code starts by including the accounts and customer classes after opening up a session:

A new object is then created:

Some variables are also declared. These two variables will be used to store error information:

Finally we check if the form has been submitted, then we validate the submitted data. The validation process involves checking if the data is empty or not and checking if the data is of the right type:

If no errors have been detected, then we continue to add the amount that the user wants to deposit to the balance of the account and store it in the $newbal variable:

Then we update the balance, using the setbalance() method that we discussed earlier:

The setbalance() method returns either true or false, depending on the query that it runs, so we test the $w variable to see which of the two it contains:

If all is well, the customer is transferred to the depositdone.php page that will display the outcome of the transaction:

The HTML portion of the script is identical to that of the withdraw script. Therefore, we will not spend much time going through its code. Basically, once the user selects the deposit option on the home page, this script is opened up and the account number is transferred to it. The form elements capture the account number and use it to run the currbalance() method. This method retrieves the current balance of the account and stores it in a hidden field of the form. The data is then sent to the PHP portion of the page and processed:

The account number, sent over from the homepage, is captured here and added to the currbalance() method:

Then it is stored in the hidden form element:

The amount that the user wants to deposit is stored in the form field:

The HTML form and table is then closed:

When the customer has made the deposit, he or she is transferred to a page called depositdone.php. That page has the following code:

Most of the HTML should be familiar to you by now, so I will only focus on the PHP section of the form that actually displays the out come of the transaction.:

The code above simply displays the new balance of the account. Below is a screen of the depositdone.php script:

Figure 2

In the next section, we will look at the customer profile script.


[next]

Recent Articles

WebReference.com site name
Use Web Caching to Make Your Web Site Faster
Creating an Online Shopping Cart Mechanism in PHP
Log JavaScript Errors Using an AJAX-driven Web Service
internet.com site name
Configuring Granular Settings for a Database Level Audit
The Perils of a Web 2.0 Transition on Your Business Processes
Facebook Redesigns Site —Again — Nears 400M Mark



The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers