Thursday, 30 August 2007

Home Page: Search, Navigation links and layout



URL: TOYSTORE: TOYS FOR UNDER 5yrs: http://www.toys4under5.com
URL on London Met webserver: http://cctmdev.londonmet.ac.uk/phr004/coursework1/default.asp

Key words: toys, baby, kids, games, play, quality & safe toys, toystore, bathtoys, imaginative toys, animal & wildlife toys etc etc.....

Description: Toystore, quality and safe toys for kids and baby, affordable price..

Validation code: storefuncs.asp page

Form Validation:


Storefuncs.asp page as mentioned earlier contains all the important functions and routines which do the validation of forms, customer login and new user registration to the database.

For new user registration, storefuncs.asp calls on the addUser subroutine which retrieves all the registration form fields, validates the field data, add the new user information to the user table on the database and adds cookies to the user’s browser.

As a mean to test all the form validations, I conducted series of tests and the result was in the following table:

3: Checkout and form validation:




Checking out proceeds from clicking the Checkout Button in the shopping cart. As the customer checks out, two things must happen. Firstly all the items in the shopping cart must be transferred to the Order table and secondly, the items must be deleted from the Shopping cart. While completing the checkout phase, the customer must follow all the required steps, otherwise transaction will not be completed.

In a ASP page, there are three different methods of using transactions, i.e. creating transactional Active Server Pages, creating ADO transactions or using database transactions.
Using transactional ASP page, if one step fails in transaction, all the earlier steps are rolled back, avoiding loss of money.

I created transactional ASP page by including the @TRANSACTION directive at the top of the page in the first line.

Completing the Checkout or Order:

Once the customer finishes shopping and clicks on the Checkout button on the Shopping cart page, the customer is presented with – firstly a page (doCheckout.asp) with a form, which enables the customer to check his/her personal details such as name, address and credit card details and confirm the order. After that, a new page (dpCheckout2.asp) will be displayed thanking the customer for putting the order, whereby the items in the shopping cart are transferred to the Orders table. With this a customer completes putting an order!

Since I have changed the Customer registration information to my own choosing as in the UK, we don not have state, or city or zip in the address, I changed City to County, deleted the State section and changed Zip to Post Code. While doing these changes and tested the page, I did come across few problems of which I intend to discuss below.

In register.asp page, I also had to change as same as the above which I did by changing the code as follows:
<.%
newusername = TRIM( Request( "newusername" ) )
newpassword = TRIM( Request( "newpassword" ) )
email = TRIM( Request( "email" ) )
street = TRIM( Request( "street" ) )
county = TRIM( Request( "county" ) )
postcode = TRIM( Request( "postcode" ) )
cctype = Request( "cctype" )
ccnumber = TRIM( Request( "ccnumber" ) )
ccexpires = TRIM( Request( "ccexpires" ) )
ccname = TRIM( Request( "ccname" ) )

s.ubmitpage = Request.ServerVariables( "SCRIPT_NAME" )
%>



County :
<.input name="county" id="county"
value="<.%=Server.HTMLEncode( county )%>" size=20 maxlength=50>


Post Code:
<.input name="postcode" id="postcode"
value="<%=Server.HTMLEncode( postcode )%>" size=20 maxlength=20>
<./font>

Payment Information:


Similarly I have to change whole lot of codes in the storefunc.asp page as it contains all the routines and functions which manage and take care of all the functionalities in other pages i.e. checking forms, user registrations, check out procedure etc.

Shopping Cart Functionality & errors resolution



For my shopping cart, it is basically simple. The functionality of it is that when a customer clicks on Add to cart button on a product page, log in page or registration page (if a new customer) will be displayed. If the log in is correct or the registration is completed successfully, the selected product information would be added to an array contained a session variable named cart (if shopping cart is created using session variable) or addcart.asp page will be displayed ( if the 'shopping cart is created using database table).

I tried creating shopping cart in both ways- using session variable as well as using database table. However later on, I decided to use the one I created using database table. This is because there are some major drawbacks with the shopping cart created using session variables. Notably session variables depend on cookies which not all browsers reliably support and the other thing is that session variables do time-out after a preset period of time.

Problems: While creating the shopping cart, I did come across numerous errors, especially as I have to change the codes of cart created using session variables to the new one which would use database table to create the cart. I have also problems implementing the delete feature of the shopping card, as well as showing product price on all the pages which I will be discussing in the following error and solution section.

CART.ASP/ PRODUCT.ASP PAGE ERRORS:
HTTP Error 405
405 Method Not Allowed
The method specified in the Request Line is not allowed for the resource identified by the request. Please ensure that you have the proper MIME type set up for the resource you are requesting.
Please contact the server's administrator if this problem persists.

Hint: This error comes up when I click on the Add to cart button. The error message is not clear where the error is located, which it normally comes out with error names and page name with line number.

Since it happened after clicking on the Add To Cart button, I suspect there might be errors in the code with my addCart.asp page or product.asp page.

Solution: I found the mistakes in Product.asp page, which has link to the addCart.asp. The follow code has to be replaced with the code in blue color to fix this problem.


'<.form method="post" action=".sessionCart.asp”>
'<.input name="pid" type="hidden" value="<%=RS (“product_id”) %>">
'<.input name="productName" type="hidden” value="<%=RS( "product_name" )%>">
'<.input name="productPrice" type="hidden” value="<%=RS( "product_price" )%>">
'



'

'


'<.input name="pid" type="hidden" value="<.%=RS( "product_id" )%'>">
'
'




'<%=RS( "product_fullDesc" )%>

'

' <.input name="pid" type="hidden" value="<%=RS( "product_id" )%>">
'
'




Error: At first My shopping cart have no facility for deleting a product from the shopping list which is not quiet as user friendly as it should be as can be seen from this diagram;


The code causing this error was:
<'%
FOR i = 0 TO UBOUND( localCart, 2 )
IF localCart( CARTPID, i ) <> "" THEN
orderTotal = orderTotal + ( localCart( CARTPPRICE, i ) * localCart( CARTPQUANTITY, i ) )
%'>


<.%=Server.HTMLEncode( localCart( CARTPNAME, i ) )%.>


<.%=formatCurrency( localCart( CARTPPRICE, i ) )%>


'<.input name="pq<%=localCart( CARTPID, i )%>" type="text" size=4
value="<%=localCart( CARTPQUANTITY, i )%>">




Solution:
To resolve this problem, I added the codes in the blue color in the following codes.
<.%
FOR i = 0 TO UBOUND( localCart, 2 )
IF localCart( CARTPID, i ) <> "" THEN
orderTotal = orderTotal + ( localCart( CARTPPRICE, i ) * localCart( CARTPQUANTITY, i ) )
%.>


'<.%=Server.HTMLEncode( localCart( CARTPNAME, i ) )%>


'<.%=formatCurrency( localCart( CARTPPRICE, i ) )%>


'<.input name="pq<%=localCart( CARTPID, i )%>" type="text" size=4
value="<%=localCart( CARTPQUANTITY, i )%>">
'<.input name="pd<%=localCart( CARTPID, i )%>" type="checkbox" value="1"> Delete



After adding the lines in the code, I get the following desired shopping cart!!


Problems with the shopping card delete section:
ADODB.Recordset error '800a0cc1'
Unknown runtime error
/phr004/coursework1/addCart.asp, line 42
Solution: Resolved by typing in card_id in the line below:
RS.Open sqlString
WHILE NOT RS.EOF
newQ = TRIM( Request( "pq" & RS( "cart_id" ) ) )
deleteProduct = TRIM( Request( "pd" & RS( "cart_id" ) ) )
IF newQ = "" OR newQ = "0" OR deleteProduct <> "" THEN
RS.Delete
ELSE
IF isNumeric( newQ ) THEN
RS( "cart_quantity" ) = newQ
END IF

Shopping Cart

2: The shopping cart:

To process the customer orders, I would require the following tables in the main database so that the while shopping, these tables help keep track of individual customer details, order details, cart details etc. Therefore I have created tables for Users, Carts and Orders as in the diagram below;

When a customer clicks on the Add to Cart button on a product page, cart.asp page is brought up which will then do either of two things, one if a customer has already registered, he or she can log in, thereby displaying addcart.asp page; otherwise, registration page will be displayed.

In the cart.asp page, I have included two files;

“aovbs.inc” contains all the constants for the ActiveX Data Objects and storefuncs.asp page has all the common functions and subroutines used in the shopping experience and evaluating all sorts of forms.

The following codes are used to retrieve productID and username and password.

..<,%,,

' Get Product ID

productID = TRIM( Request( "pid" ) )

' Get Login Information

username = TRIM( Request( "username" ) )

password = TRIM( Request( "password" ) )

register = TRIM( Request( "register" ) )

error = TRIM( Request( "error" ) )

Following codes are used to add new customer registration information to the database as well as to log in registered customers, by checking username and passwords. If the log in is successful, addcart.asp is displayed and otherwise, register.asp page is displayed to register a new customer. The functions which checks username and passwords is included in another page called storefunc.asp.


‘ Check For New Registration

IF register <> “” AND error = “” THEN

addUser

END IF

Get User ID

userID = checkpassword( username, password, Con )

IF userID > 0 THEN

..%>


Feed back error:

Microsoft OLE DB Provider for ODBC Drivers error '80040e0c'

Command text was not set for the command object.

/phr004/coursework1/saveFeedback.asp, line 15

Solution:

sqlString = "INSERT INTO feedback ( feedback_email, feedback_comment ) " &_

"VALUES ('" & fixQuotes ( email ) & "','" & fixQuotes( comment ) & "')"

dsnCon.Execute sqlString