
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" )%>">
'
'
'<%=RS( "product_fullDesc" )%>
'
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
No comments:
Post a Comment