I
isaac2004
hi i am creating a basic asp site that uses cookies to manage a cart
for an online store. whenever i open this page without adding anything
to the cart. i get an error message.
here is my code
<%@ Language=VBScript %>
<% Option Explicit %>
<!--#include file="DatabaseConnect.asp"-->
<!--#include virtual="06winter/levini/database/adovbs.inc"-->
<html>
<head><title>Shopping Cart</title>
<link rel="stylesheet" href="BookStore.css" type="text/css">
</head>
<table>
<!-- Header SSI starts here-->
<!--#include file="header.html"-->
<!-- Header SSI ends here-->
<!-- Author SSI begins here-->
<!--#include file="ListAuthors.asp"-->
<!-- Author SSI ends here-->
<%
'This shopping cart uses a cookie named "ShoppingCart"
'to store the ISBNs of the items in the cart.
'The cookie puts each ISBN value into a separate key named ISBN1,
ISBN2, etc.
'The current number of items in the cart is stored in a key named
"ItemCount"
dim ISBN, iItemCount, iItem, iCount, bFound, curPrice, curDiscPrice,
strSQL, objRS, strTitle, dblPrice, dblShipping, dblSubTotal,
dblTotalPrice
ISBN = trim(Request.QueryString("isbn"))
'sql statement for individual books
strSQL = "SELECT tblBookDescription.ISBN,
tblBookDescription.strTitle, tblBookDescription.strDescription,
tblBookDescription.strPublisher, tblBookDescription.dblPrice,
tblAuthors.AuthorID " & _
"FROM tblAuthors INNER JOIN (tblBookDescription INNER JOIN
tblAuthorsBooks ON tblBookDescription.ISBN = tblAuthorsBooks.ISBN) ON
tblAuthors.AuthorID = tblAuthorsBooks.AuthorID " & _
"WHERE (((tblBookDescription.ISBN)='" & ISBN & "')); "
response.write("strSQL = " & strSQL)
Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.open strSQL, objConn
'Initialize iItemCount with number of books in the cart
If request.cookies("ShoppingCart").HasKeys then
iItemCount = request.cookies("ShoppingCart")("ItemCount")
else
'No cookie yet
iItemCount = 0
end if
'Add items to cart
If Request("action") = "add" and len(ISBN)>5 then
'add new item to ShoppingCart
iItemCount = iItemCount + 1
Response.cookies("ShoppingCart")("ISBN"&iItemCount) = ISBN
end if
'Delete items from Cart
If Request.QueryString("action") = "del" and len(ISBN)>5 then
'find the isbn
bFound = "False"
iItem = 1
Do while NOT bFound and iItem <= iItemCount
If Request.Cookies("ShoppingCart")("ISBN"&iItem) = ISBN then
bFound = "True"
else
iItem = iItem + 1
End If
Loop
If bFound then
'replace the deleted item with the item above it
iItemCount=iItemCount - 1
For iCount = iItem to iItemCount
Response.Cookies("ShoppingCart")("ISBN" &iCount)= _
Request.Cookies("ShoppingCart")("ISBN"&iCount+1)
Next
else
Response.write "Error: Could not match ISBN to delete."
end if
End If
'Update iItemCount
Response.Cookies("ShoppingCart")("ItemCount")=iItemCount
Response.Cookies("ShoppingCart").Expires = Date + 30
'
***********************************************************************************
' You do not need to modify anything above this line.
' You will need to modify the table below to list the items
' in your cart, calculate, total costs, etc.
'
***********************************************************************************
' list items in shopping cart
If iItemCount < 1 then
response.write "<center><font face='Comic Sans MS'
color='#FF0000'>" & _
"Your Shopping Cart is empty.</font><br><br>"
Else
%>
<div align="center">
<center>
<font face='Comic Sans MS' color='#FF0000'>You have <%
=iItemCount %>
book<% If iItemCount > 1 then response.write "s"%> in
your shopping cart.
</font><br><br>
<table border="0" cellpadding="5" cellspacing="0"
width="643">
<tr>
<%
'List each item in cart
For iCount = 1 to iItemCount
ISBN =
Request.Cookies("ShoppingCart")("ISBN"&iCount)
%>
<tr>
<td valign="top" width="20" >1.</td>
<td valign="top" width="256">
<! Book Title, author, stock >
<a href="ProductPage.asp?isbn= <% =objRS("ISBN")%> ">
<% =objRS("strTitle")%></a>
<br>
<font size="-1">
by <% =funListAuthors(objRS("ISBN")) %></a>
</font>
<br>
</td>
<td valign="top" align="center" width="66">1</td>
<td valign="top" width="179">
<! Price >
<FONT face=arial,verdana,helvetica><B>List Price:
<font color=#990000><strike><% =dblPrice
%></strike></font><br>
<FONT face=arial,verdana,helvetica>Our Price:
<font color=#990000><% =curDiscPrice %></font><br>
<FONT face=arial,verdana,helvetica>You Save:
<font color=#990000><% =FormatCurrency((dblPrice -
curDiscPrice)) %>(20%)</b></font><br><br>
</td>
<td valign="top" width="62" >
<a
href="ShoppingCart.asp?ISBN=<%=objRS("ISBN")%>&action=del"> Remove</a>
</td>
</tr>
<% Next
%> </table>
</center>
<%End If
%>
<tr>
<td></td><td></td><td></td>
<td>
<FONT face=arial,verdana,helvetica>
<table border="0" cellpadding="0" cellspacing="0"
width="150" >
<tr>
<% dim i
-----------------------------------------------------error here
curPrice = FormatCurrency(objRS("dblPrice"))
curDiscPrice = FormatCurrency((objRS("dblPrice")*.8))
dblPrice = (objRS("dblPrice"))
'response.write(iItemCount)
dblSubTotal = 0
for i = 1 to iItemCount
dblSubTotal = dblSubTotal + curDiscPrice
next
dblShipping = 3.49 + ((iItemCount - 1) * .99)
dblTotalPrice = dblShipping + dblSubTotal
if iItemCount = 0 then
response.write("<br>")
else
%>
<td width="75">Sub-Total:</td>
<td width="75"><p align="right"><%
=dblSubTotal%></td>
</tr>
<tr>
<td width="75">Shipping*:</td>
<td width="75"><p align="right"><% =dblShipping
%></td>
</tr>
<tr>
<td width="75">Total:</td>
<td width="75"><p align="right"><%
=dblTotalPrice%></td>
</tr>
</table>
</td>
</tr>
</table>
</center>
</div>
<% end if%>
</table>
<br>
<div align="center">
<center>
<table border="0" cellpadding="5" cellspacing="0" width="400"
bgcolor="#99CCFF">
<tr>
<td><a href="default.asp"><img border="0"
src="/06Winter/levini/images/continue-shopping.gif" width="121"
height="19"></a><br>
</td>
<td>
<p align="right"><a href="checkout.asp"><img border="0"
src="/06Winter/levini/images/proceed-to-checkout.gif" width="183"
height="31"></a>
</td>
</tr>
</table>
<table border="0" cellpadding="5" cellspacing="0" width="400">
<tr>
<td> <br><p align=center> Shipping is $3.49 for the first book
and $.99 for each additional book. To assure reliable delivery and
to keep your costs low we send all books via UPS ground.
</td>
</tr>
</table>
</body>
</html>
any help would be much appreciated thank you
for an online store. whenever i open this page without adding anything
to the cart. i get an error message.
here is my code
<%@ Language=VBScript %>
<% Option Explicit %>
<!--#include file="DatabaseConnect.asp"-->
<!--#include virtual="06winter/levini/database/adovbs.inc"-->
<html>
<head><title>Shopping Cart</title>
<link rel="stylesheet" href="BookStore.css" type="text/css">
</head>
<table>
<!-- Header SSI starts here-->
<!--#include file="header.html"-->
<!-- Header SSI ends here-->
<!-- Author SSI begins here-->
<!--#include file="ListAuthors.asp"-->
<!-- Author SSI ends here-->
<%
'This shopping cart uses a cookie named "ShoppingCart"
'to store the ISBNs of the items in the cart.
'The cookie puts each ISBN value into a separate key named ISBN1,
ISBN2, etc.
'The current number of items in the cart is stored in a key named
"ItemCount"
dim ISBN, iItemCount, iItem, iCount, bFound, curPrice, curDiscPrice,
strSQL, objRS, strTitle, dblPrice, dblShipping, dblSubTotal,
dblTotalPrice
ISBN = trim(Request.QueryString("isbn"))
'sql statement for individual books
strSQL = "SELECT tblBookDescription.ISBN,
tblBookDescription.strTitle, tblBookDescription.strDescription,
tblBookDescription.strPublisher, tblBookDescription.dblPrice,
tblAuthors.AuthorID " & _
"FROM tblAuthors INNER JOIN (tblBookDescription INNER JOIN
tblAuthorsBooks ON tblBookDescription.ISBN = tblAuthorsBooks.ISBN) ON
tblAuthors.AuthorID = tblAuthorsBooks.AuthorID " & _
"WHERE (((tblBookDescription.ISBN)='" & ISBN & "')); "
response.write("strSQL = " & strSQL)
Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.open strSQL, objConn
'Initialize iItemCount with number of books in the cart
If request.cookies("ShoppingCart").HasKeys then
iItemCount = request.cookies("ShoppingCart")("ItemCount")
else
'No cookie yet
iItemCount = 0
end if
'Add items to cart
If Request("action") = "add" and len(ISBN)>5 then
'add new item to ShoppingCart
iItemCount = iItemCount + 1
Response.cookies("ShoppingCart")("ISBN"&iItemCount) = ISBN
end if
'Delete items from Cart
If Request.QueryString("action") = "del" and len(ISBN)>5 then
'find the isbn
bFound = "False"
iItem = 1
Do while NOT bFound and iItem <= iItemCount
If Request.Cookies("ShoppingCart")("ISBN"&iItem) = ISBN then
bFound = "True"
else
iItem = iItem + 1
End If
Loop
If bFound then
'replace the deleted item with the item above it
iItemCount=iItemCount - 1
For iCount = iItem to iItemCount
Response.Cookies("ShoppingCart")("ISBN" &iCount)= _
Request.Cookies("ShoppingCart")("ISBN"&iCount+1)
Next
else
Response.write "Error: Could not match ISBN to delete."
end if
End If
'Update iItemCount
Response.Cookies("ShoppingCart")("ItemCount")=iItemCount
Response.Cookies("ShoppingCart").Expires = Date + 30
'
***********************************************************************************
' You do not need to modify anything above this line.
' You will need to modify the table below to list the items
' in your cart, calculate, total costs, etc.
'
***********************************************************************************
' list items in shopping cart
If iItemCount < 1 then
response.write "<center><font face='Comic Sans MS'
color='#FF0000'>" & _
"Your Shopping Cart is empty.</font><br><br>"
Else
%>
<div align="center">
<center>
<font face='Comic Sans MS' color='#FF0000'>You have <%
=iItemCount %>
book<% If iItemCount > 1 then response.write "s"%> in
your shopping cart.
</font><br><br>
<table border="0" cellpadding="5" cellspacing="0"
width="643">
<tr>
Book</font></td>
Quantity</font></td>
Price</font></td>
</tr>Remove</font></td>
<%
'List each item in cart
For iCount = 1 to iItemCount
ISBN =
Request.Cookies("ShoppingCart")("ISBN"&iCount)
%>
<tr>
<td valign="top" width="20" >1.</td>
<td valign="top" width="256">
<! Book Title, author, stock >
<a href="ProductPage.asp?isbn= <% =objRS("ISBN")%> ">
<% =objRS("strTitle")%></a>
<br>
<font size="-1">
by <% =funListAuthors(objRS("ISBN")) %></a>
</font>
<br>
</td>
<td valign="top" align="center" width="66">1</td>
<td valign="top" width="179">
<! Price >
<FONT face=arial,verdana,helvetica><B>List Price:
<font color=#990000><strike><% =dblPrice
%></strike></font><br>
<FONT face=arial,verdana,helvetica>Our Price:
<font color=#990000><% =curDiscPrice %></font><br>
<FONT face=arial,verdana,helvetica>You Save:
<font color=#990000><% =FormatCurrency((dblPrice -
curDiscPrice)) %>(20%)</b></font><br><br>
</td>
<td valign="top" width="62" >
<a
href="ShoppingCart.asp?ISBN=<%=objRS("ISBN")%>&action=del"> Remove</a>
</td>
</tr>
<% Next
%> </table>
</center>
<%End If
%>
<tr>
<td></td><td></td><td></td>
<td>
<FONT face=arial,verdana,helvetica>
<table border="0" cellpadding="0" cellspacing="0"
width="150" >
<tr>
<% dim i
-----------------------------------------------------error here
curPrice = FormatCurrency(objRS("dblPrice"))
curDiscPrice = FormatCurrency((objRS("dblPrice")*.8))
dblPrice = (objRS("dblPrice"))
'response.write(iItemCount)
dblSubTotal = 0
for i = 1 to iItemCount
dblSubTotal = dblSubTotal + curDiscPrice
next
dblShipping = 3.49 + ((iItemCount - 1) * .99)
dblTotalPrice = dblShipping + dblSubTotal
if iItemCount = 0 then
response.write("<br>")
else
%>
<td width="75">Sub-Total:</td>
<td width="75"><p align="right"><%
=dblSubTotal%></td>
</tr>
<tr>
<td width="75">Shipping*:</td>
<td width="75"><p align="right"><% =dblShipping
%></td>
</tr>
<tr>
<td width="75">Total:</td>
<td width="75"><p align="right"><%
=dblTotalPrice%></td>
</tr>
</table>
</td>
</tr>
</table>
</center>
</div>
<% end if%>
</table>
<br>
<div align="center">
<center>
<table border="0" cellpadding="5" cellspacing="0" width="400"
bgcolor="#99CCFF">
<tr>
<td><a href="default.asp"><img border="0"
src="/06Winter/levini/images/continue-shopping.gif" width="121"
height="19"></a><br>
</td>
<td>
<p align="right"><a href="checkout.asp"><img border="0"
src="/06Winter/levini/images/proceed-to-checkout.gif" width="183"
height="31"></a>
</td>
</tr>
</table>
<table border="0" cellpadding="5" cellspacing="0" width="400">
<tr>
<td> <br><p align=center> Shipping is $3.49 for the first book
and $.99 for each additional book. To assure reliable delivery and
to keep your costs low we send all books via UPS ground.
</td>
</tr>
</table>
</body>
</html>
any help would be much appreciated thank you