Chapter 9 Building the Shopping cart

Download Report

Transcript Chapter 9 Building the Shopping cart

Chapter 9
Building the Shopping cart
Objective
 Creating
Shopping cart using session
Variable.
 Creating a shopping cart using a database
table.
 Use the native methods of the ADO to
add, delete & update records in a
recordset.
Using session Variable to create a
Shopping cart
Every products selected by the customer is add to
a cart called shopping cart.
One way to create shopping cart is by assigning an
array to session variable.
New items can be added o a shopping cart or
existing items can be removed.
This isn’t the best method of creating shopping
cart bcoz the shopping cart relies on session
variables & sessions variables are notoriously
unreliable.
Contd…
When the visitor first arrives at a Web site that
uses Session variables, the Web Server adds a
cookie to the visitor’s browser that tracks the
visitor as he moves from page to page.
When the session variable is created, this cookie is
used to associate the variable with the proper user.
If, for whatever reason, the cookie cannot be
created on the user’s browsers, the session
variables won’t work
Reasons that prevent cookie from being added to a
user’s browser.
Some older browser simply don’t support cookies.
The recent browsers provide an option to accept or
refuse cookies.
The user’s cookie file may be corrupted.
They time out after a preset period o time [default
20 min].
Advantage is you need not force the customer to
register or log in before adding items to a
shopping cart.
Using Database table to create a
shopping cart
First create a table..
Let us create a table named cart and the
following is the schema:
Cart_id
Cart_userid
Cart_productid
Cart_quantity
Contd…
As the user selects the product the registration
form /log in form is displayed to accept the user’s
details along with credit card details.
Every product selected is added to the table just
created.
Shopping cart created here is permanent.
Doesn’t rely on the properties of a user’s browser.
Not a single cookie is used.
Native ADO Methods
This is the second method of using the ADO o
work with a database.
Native methods of ADO are used to modify
database records instead of using the ADO to pass
SQL strings to a database.
There is no need of alternative method but in
certain situations it is more convenient.
Multiple records in a database table can be
updated easily using native methods of ADO.
Creating Updateable Recordset
To modify the records in the Recordset, you must
open the Recordset in such a way that it is
updateable.
By default the Recordset is read only.
You can open a modifiable Recordset by changing
the Recordset’s LockType property.
Statement to open record set:

RS.LockType=adOpenOptimistic
Results in the least interference with other users
and is least likely to cause database deadlock.
LockType Property values
adLockReadOnly
adLockPessimistic
adLockOptimistic
adLockBatchOptimistic