|
 |
asp_databases thread: question
Message #1 by shohokukj@y... on Fri, 15 Nov 2002 15:39:20
|
|
I'm having problem with this coding. This file keeps showing this error
ADODB.Recordset error '800a0e79'
The operation requested by the application is not allowed if the object is
open.
/ProductList.asp, line 5
The codes are given below.
<%
strsql = "SELECT car_id, model, car_pic, price " &_
"FROM spec WHERE car_cat='" & cat & "' " &_
"ORDER BY model "
rst.open strsql,con,1,3
%>
<table width="350" border=0
cellpadding=5 cellspacing=0>
<%
WHILE NOT rst.EOF
%>
<tr>
<td>
<% IF rst( "car_pic" ) <> "?????" THEN %>
<IMG SRC="<%=rst( "car_pic" )%>"
HSPACE=4 VSPACE=4 BORDER=0 align="center">
<% END IF %>
</td>
<td>
<%=rst( "car_id" )%>
<b><%=rst( "model" )%></b></a>
<br><%=rst( "price" )%>
</td>
</tr>
<tr>
<td colspan=2 align="center">
</td>
</tr>
<%
rst.MoveNext
WEND
rst.close
%>
</table>
Please go through them and provide a solution for me. Thanks to whoever
may be.
Message #2 by "Kim" <kimiwan@k...> on Fri, 15 Nov 2002 17:16:24 +0100
|
|
There must be more code than that - where do you instantiate rst? You're
probably both instantiating and opening it elsewhere, but forget to close
it.
-Kim
> -----Original Message-----
> From: shohokukj@y... [mailto:shohokukj@y...]
> Sent: 15. november 2002 15:39
> To: ASP Databases
> Subject: [asp_databases] question
>
>
> I'm having problem with this coding. This file keeps showing this error
>
> ADODB.Recordset error '800a0e79'
>
> The operation requested by the application is not allowed if the
> object is
> open.
>
> /ProductList.asp, line 5
>
> The codes are given below.
> <%
> strsql = "SELECT car_id, model, car_pic, price " &_
> "FROM spec WHERE car_cat='" & cat & "' " &_
> "ORDER BY model "
> rst.open strsql,con,1,3
>
> %>
> <table width="350" border=0
> cellpadding=5 cellspacing=0>
> <%
> WHILE NOT rst.EOF
> %>
> <tr>
> <td>
> <% IF rst( "car_pic" ) <> "?????" THEN %>
> <IMG SRC="<%=rst( "car_pic" )%>"
> HSPACE=4 VSPACE=4 BORDER=0 align="center">
> <% END IF %>
> </td>
> <td>
> <%=rst( "car_id" )%>
> <b><%=rst( "model" )%></b></a>
> <br><%=rst( "price" )%>
> </td>
> </tr>
> <tr>
> <td colspan=2 align="center">
>
> </td>
> </tr>
> <%
> rst.MoveNext
> WEND
> rst.close
> %>
> </table>
>
> Please go through them and provide a solution for me. Thanks to whoever
> may be.
>
>
>
>
>
>
>
>
Message #3 by shohokukj@y... on Fri, 15 Nov 2002 16:41:46
|
|
Actually,the whole file is here. Can you please go through it and tell me
what is wrong? Thanks a lot! I need it urgently.
Default.asp:
<!-- #INCLUDE FILE="adovbs.inc" -->
<!-- #INCLUDE FILE="opendb.asp" -->
<%
' Get Current Category
cat = TRIM( Request( "cat" ) )
IF cat = "" THEN cat = "Home"
%>
<html>
<head>
<title>BestCars</title>
</head>
<body link="#ff4040" vtext="lightred" bgcolor="#ffffff">
<center>
<table width=640 border=0 bgcolor="#ffffff"
cellspacing=0 cellpadding=0>
<tr>
<td>
<img src="images\bestcar.gif">
</td>
<td align=right valign="bottom">
<a href="cart.asp">shopping cart</a>
|
<a href="account.asp">account</a>
</td>
</tr>
<tr>
<td colspan=2>
<hr width="640">
</td>
</tr>
</table>
<tr>
<td>
</td>
</tr>
<tr align="left">
<td valign="top">
<img src="images\Categories.gif" vspace=0 border=0></td>
</tr>
<tr>
<td>
<table width="200" cellpadding=4 cellspacing=0
bgcolor="lightyellow" border=1>
<tr>
<td>
<font size="3"><b>
<!-- #INCLUDE FILE="CatList.asp" -->
</b></font>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td><td valign="top">
<% IF cat = "Home" THEN %>
<% ELSE %>
<!-- #INCLUDE FILE="ProductList.asp" -->
<% END IF %>
</td></tr>
</table>
<!-- #INCLUDE FILE="closedb.asp" -->
<hr width=640>
<H5>Copyright © 2002 BestCars.com. All Rights Reserved<br>
All information contained here in applies to Singapore Vehicles
Only<br></H5>
</center>
</body>
</hmtl>
Productlist.asp:
<%
strsql = "SELECT car_id, model, car_pic, price " &_
"FROM spec WHERE car_cat='" & cat & "' " &_
"ORDER BY model "
rst.open strsql,con,1,3
%>
<table width="350" border=0
cellpadding=5 cellspacing=0>
<%
WHILE NOT rst.EOF
%>
<tr>
<td>
<% IF rst( "car_pic" ) <> "?????" THEN %>
<IMG SRC="<%=rst( "car_pic" )%>"
HSPACE=4 VSPACE=4 BORDER=0 align="center">
<% END IF %>
</td>
<td>
<%=rst( "car_id" )%>
<b><%=rst( "model" )%></b></a>
<br><%=rst( "price" )%>
<form method="post" action="cart.asp">
<input name="carid" type="hidden" value="<%=rst( "car_id" )%>">
<input type="submit" value="Add To Cart">
</form>
</td>
</tr>
<tr>
<td colspan=2 align="center">
</td>
</tr>
<%
rst.MoveNext
WEND
rst.close
%>
</table>
Catlist.asp:
<%
strsql="select DISTINCT car_cat from spec"
rst.open strsql,con,1,3
%>
<% If cat = "Home" THEN %>
<font color="red"><b>Home</b></font>
<UL>
<% ELSE %>
<a href="default.asp?cat=Home">Home</a>
<UL>
<% END IF %>
<% WHILE NOT rst.EOF %>
<% IF rst( "car_cat" ) = cat THEN %>
<li><font color="red"><b>
<%=rst( "car_cat" )%>
</b></font>
<% ELSE %>
<li><a href="default.asp?cat=<%=Server.URLEncode( rst( "car_cat" ) )%>"><%
=rst( "car_cat" )%></a>
<% END IF %>
<%
rst.MoveNext
WEND
%>
</UL>
opendb.asp:
<%
dim con,rst
set con = server.createobject("ADODB.Connection")
set rst = server.createobject("ADODB.Recordset")
con.open "Driver={Microsoft Access Driver (*.mdb)};Dbq=" & Server.MapPath
("cars.mdb")
%>
Closedb.asp:
<%
set rst = nothing
set con = nothing
%>
> There must be more code than that - where do you instantiate rst? You're
probably both instantiating and opening it elsewhere, but forget to close
it.
-Kim
> -----Original Message-----
> From: shohokukj@y... [mailto:shohokukj@y...]
> Sent: 15. november 2002 15:39
> To: ASP Databases
> Subject: [asp_databases] question
>
>
> I'm having problem with this coding. This file keeps showing this error
>
> ADODB.Recordset error '800a0e79'
>
> The operation requested by the application is not allowed if the
> object is
> open.
>
> /ProductList.asp, line 5
>
> The codes are given below.
> <%
> strsql = "SELECT car_id, model, car_pic, price " &_
> "FROM spec WHERE car_cat='" & cat & "' " &_
> "ORDER BY model "
> rst.open strsql,con,1,3
>
> %>
> <table width="350" border=0
> cellpadding=5 cellspacing=0>
> <%
> WHILE NOT rst.EOF
> %>
> <tr>
> <td>
> <% IF rst( "car_pic" ) <> "?????" THEN %>
> <IMG SRC="<%=rst( "car_pic" )%>"
> HSPACE=4 VSPACE=4 BORDER=0 align="center">
> <% END IF %>
> </td>
> <td>
> <%=rst( "car_id" )%>
> <b><%=rst( "model" )%></b></a>
> <br><%=rst( "price" )%>
> </td>
> </tr>
> <tr>
> <td colspan=2 align="center">
>
> </td>
> </tr>
> <%
> rst.MoveNext
> WEND
> rst.close
> %>
> </table>
>
> Please go through them and provide a solution for me. Thanks to whoever
> may be.
>
>
>
>
>
>
>
>
Message #4 by "Kim" <kimiwan@k...> on Fri, 15 Nov 2002 21:38:32 +0100
|
|
In catlist.asp, you open the recordset but forget to close it again - that's
why you get the error "The operation requested by the application is not
allowed if the object is open." in productlist.asp when you try to open the
recordset, which is already open.
-Kim
> -----Original Message-----
> From: shohokukj@y... [mailto:shohokukj@y...]
> Sent: 15. november 2002 16:42
> To: ASP Databases
> Subject: [asp_databases] RE: question
>
>
> Actually,the whole file is here. Can you please go through it and tell me
> what is wrong? Thanks a lot! I need it urgently.
>
> Default.asp:
>
> <!-- #INCLUDE FILE="adovbs.inc" -->
> <!-- #INCLUDE FILE="opendb.asp" -->
> <%
> ' Get Current Category
> cat = TRIM( Request( "cat" ) )
> IF cat = "" THEN cat = "Home"
>
> %>
> <html>
> <head>
> <title>BestCars</title>
> </head>
> <body link="#ff4040" vtext="lightred" bgcolor="#ffffff">
> <center>
>
> <table width=640 border=0 bgcolor="#ffffff"
> cellspacing=0 cellpadding=0>
> <tr>
> <td>
> <img src="images\bestcar.gif">
> </td>
> <td align=right valign="bottom">
> <a href="cart.asp">shopping cart</a>
> |
> <a href="account.asp">account</a>
> </td>
> </tr>
> <tr>
> <td colspan=2>
> <hr width="640">
> </td>
> </tr>
> </table>
>
>
> <tr>
> <td>
>
> </td>
> </tr>
> <tr align="left">
> <td valign="top">
> <img src="images\Categories.gif" vspace=0 border=0></td>
> </tr>
> <tr>
> <td>
> <table width="200" cellpadding=4 cellspacing=0
> bgcolor="lightyellow" border=1>
> <tr>
> <td>
> <font size="3"><b>
> <!-- #INCLUDE FILE="CatList.asp" -->
> </b></font>
> </td>
> </tr>
> </table>
> </td>
> </tr>
> </table>
>
> </td><td valign="top">
> <% IF cat = "Home" THEN %>
>
> <% ELSE %>
> <!-- #INCLUDE FILE="ProductList.asp" -->
> <% END IF %>
>
> </td></tr>
> </table>
>
> <!-- #INCLUDE FILE="closedb.asp" -->
>
> <hr width=640>
> <H5>Copyright © 2002 BestCars.com. All Rights Reserved<br>
> All information contained here in applies to Singapore Vehicles
> Only<br></H5>
>
>
> </center>
> </body>
> </hmtl>
>
> Productlist.asp:
>
> <%
> strsql = "SELECT car_id, model, car_pic, price " &_
> "FROM spec WHERE car_cat='" & cat & "' " &_
> "ORDER BY model "
> rst.open strsql,con,1,3
>
> %>
> <table width="350" border=0
> cellpadding=5 cellspacing=0>
> <%
> WHILE NOT rst.EOF
> %>
> <tr>
> <td>
> <% IF rst( "car_pic" ) <> "?????" THEN %>
> <IMG SRC="<%=rst( "car_pic" )%>"
> HSPACE=4 VSPACE=4 BORDER=0 align="center">
> <% END IF %>
> </td>
> <td>
> <%=rst( "car_id" )%>
> <b><%=rst( "model" )%></b></a>
> <br><%=rst( "price" )%>
> <form method="post" action="cart.asp">
> <input name="carid" type="hidden" value="<%=rst( "car_id" )%>">
> <input type="submit" value="Add To Cart">
> </form>
> </td>
> </tr>
> <tr>
> <td colspan=2 align="center">
>
> </td>
> </tr>
> <%
> rst.MoveNext
> WEND
> rst.close
> %>
> </table>
>
> Catlist.asp:
>
> <%
> strsql="select DISTINCT car_cat from spec"
> rst.open strsql,con,1,3
> %>
> <% If cat = "Home" THEN %>
> <font color="red"><b>Home</b></font>
> <UL>
> <% ELSE %>
> <a href="default.asp?cat=Home">Home</a>
> <UL>
> <% END IF %>
> <% WHILE NOT rst.EOF %>
> <% IF rst( "car_cat" ) = cat THEN %>
> <li><font color="red"><b>
> <%=rst( "car_cat" )%>
> </b></font>
> <% ELSE %>
> <li><a href="default.asp?cat=<%=Server.URLEncode( rst( "car_cat" ) )%>"><%
> =rst( "car_cat" )%></a>
> <% END IF %>
> <%
> rst.MoveNext
> WEND
> %>
> </UL>
>
> opendb.asp:
>
> <%
> dim con,rst
> set con = server.createobject("ADODB.Connection")
> set rst = server.createobject("ADODB.Recordset")
> con.open "Driver={Microsoft Access Driver (*.mdb)};Dbq=" & Server.MapPath
> ("cars.mdb")
> %>
>
> Closedb.asp:
>
> <%
> set rst = nothing
> set con = nothing
> %>
>
>
>
>
>
> > There must be more code than that - where do you instantiate
> rst? You're
> probably both instantiating and opening it elsewhere, but forget to close
> it.
>
> -Kim
Message #5 by shohokukj@y... on Sat, 16 Nov 2002 05:13:48
|
|
Ok. Thanks a lot!
I got it.
> In catlist.asp, you open the recordset but forget to close it again -
that's
why you get the error "The operation requested by the application is not
allowed if the object is open." in productlist.asp when you try to open the
recordset, which is already open.
-Kim
> -----Original Message-----
> From: shohokukj@y... [mailto:shohokukj@y...]
> Sent: 15. november 2002 16:42
> To: ASP Databases
> Subject: [asp_databases] RE: question
>
>
> Actually,the whole file is here. Can you please go through it and tell me
> what is wrong? Thanks a lot! I need it urgently.
>
> Default.asp:
>
> <!-- #INCLUDE FILE="adovbs.inc" -->
> <!-- #INCLUDE FILE="opendb.asp" -->
> <%
> ' Get Current Category
> cat = TRIM( Request( "cat" ) )
> IF cat = "" THEN cat = "Home"
>
> %>
> <html>
> <head>
> <title>BestCars</title>
> </head>
> <body link="#ff4040" vtext="lightred" bgcolor="#ffffff">
> <center>
>
> <table width=640 border=0 bgcolor="#ffffff"
> cellspacing=0 cellpadding=0>
> <tr>
> <td>
> <img src="images\bestcar.gif">
> </td>
> <td align=right valign="bottom">
> <a href="cart.asp">shopping cart</a>
> |
> <a href="account.asp">account</a>
> </td>
> </tr>
> <tr>
> <td colspan=2>
> <hr width="640">
> </td>
> </tr>
> </table>
>
>
> <tr>
> <td>
>
> </td>
> </tr>
> <tr align="left">
> <td valign="top">
> <img src="images\Categories.gif" vspace=0 border=0></td>
> </tr>
> <tr>
> <td>
> <table width="200" cellpadding=4 cellspacing=0
> bgcolor="lightyellow" border=1>
> <tr>
> <td>
> <font size="3"><b>
> <!-- #INCLUDE FILE="CatList.asp" -->
> </b></font>
> </td>
> </tr>
> </table>
> </td>
> </tr>
> </table>
>
> </td><td valign="top">
> <% IF cat = "Home" THEN %>
>
> <% ELSE %>
> <!-- #INCLUDE FILE="ProductList.asp" -->
> <% END IF %>
>
> </td></tr>
> </table>
>
> <!-- #INCLUDE FILE="closedb.asp" -->
>
> <hr width=640>
> <H5>Copyright © 2002 BestCars.com. All Rights Reserved<br>
> All information contained here in applies to Singapore Vehicles
> Only<br></H5>
>
>
> </center>
> </body>
> </hmtl>
>
> Productlist.asp:
>
> <%
> strsql = "SELECT car_id, model, car_pic, price " &_
> "FROM spec WHERE car_cat='" & cat & "' " &_
> "ORDER BY model "
> rst.open strsql,con,1,3
>
> %>
> <table width="350" border=0
> cellpadding=5 cellspacing=0>
> <%
> WHILE NOT rst.EOF
> %>
> <tr>
> <td>
> <% IF rst( "car_pic" ) <> "?????" THEN %>
> <IMG SRC="<%=rst( "car_pic" )%>"
> HSPACE=4 VSPACE=4 BORDER=0 align="center">
> <% END IF %>
> </td>
> <td>
> <%=rst( "car_id" )%>
> <b><%=rst( "model" )%></b></a>
> <br><%=rst( "price" )%>
> <form method="post" action="cart.asp">
> <input name="carid" type="hidden" value="<%=rst( "car_id" )%>">
> <input type="submit" value="Add To Cart">
> </form>
> </td>
> </tr>
> <tr>
> <td colspan=2 align="center">
>
> </td>
> </tr>
> <%
> rst.MoveNext
> WEND
> rst.close
> %>
> </table>
>
> Catlist.asp:
>
> <%
> strsql="select DISTINCT car_cat from spec"
> rst.open strsql,con,1,3
> %>
> <% If cat = "Home" THEN %>
> <font color="red"><b>Home</b></font>
> <UL>
> <% ELSE %>
> <a href="default.asp?cat=Home">Home</a>
> <UL>
> <% END IF %>
> <% WHILE NOT rst.EOF %>
> <% IF rst( "car_cat" ) = cat THEN %>
> <li><font color="red"><b>
> <%=rst( "car_cat" )%>
> </b></font>
> <% ELSE %>
> <li><a href="default.asp?cat=<%=Server.URLEncode( rst( "car_cat" ) )%
>"><%
> =rst( "car_cat" )%></a>
> <% END IF %>
> <%
> rst.MoveNext
> WEND
> %>
> </UL>
>
> opendb.asp:
>
> <%
> dim con,rst
> set con = server.createobject("ADODB.Connection")
> set rst = server.createobject("ADODB.Recordset")
> con.open "Driver={Microsoft Access Driver (*.mdb)};Dbq=" & Server.MapPath
> ("cars.mdb")
> %>
>
> Closedb.asp:
>
> <%
> set rst = nothing
> set con = nothing
> %>
>
>
>
>
>
> > There must be more code than that - where do you instantiate
> rst? You're
> probably both instantiating and opening it elsewhere, but forget to close
> it.
>
> -Kim
Message #6 by shohokukj@y... on Sat, 16 Nov 2002 06:54:46
|
|
Sorry to trouble you again but can you help me see the add to cart portion?
Thanks!!
cart.asp:
<!-- #INCLUDE FILE="adovbs.inc" -->
<!-- #INCLUDE FILE="storefuncs.asp" -->
<%
' 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" ) )
' Check For New Registration
IF register <> "" AND error = "" THEN
addUser
END IF
' Get User ID
userID = checkpassword( username, password, Con )
IF userID > 0 THEN
%>
<!-- #INCLUDE FILE="addCart.asp" -->
<% ELSE %>
<!-- #INCLUDE FILE="register.asp" -->
<%
END IF
%>
addCart.asp:
<!-- #INCLUDE FILE="adovbs.inc" -->
<!-- #INCLUDE FILE="storefuncs.asp" -->
<%
' 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" ) )
' Check For New Registration
IF register <> "" AND error = "" THEN
addUser
END IF
' Get User ID
userID = checkpassword( username, password, Con )
IF userID > 0 THEN
%>
<!-- #INCLUDE FILE="addCart.asp" -->
<% ELSE %>
<!-- #INCLUDE FILE="register.asp" -->
<%
END IF
%>
storefuncs.asp:
<%
Dim Con
'==========================
' Common Functions
'==========================
FUNCTION fixQuotes( theString )
fixQuotes = REPLACE( theString, "'", "''" )
END FUNCTION
SUB addCookie( theName, theValue )
Response.Cookies( theName ) = theValue
Response.Cookies( theName ).Expires = "Nov 30, 2003"
Response.Cookies( theName ).Path = "/"
Response.Cookies( theName ).Secure = FALSE
END SUB
FUNCTION checkpassword( byVal username, byVal password, byRef Con )
sqlString = "SELECT user_id FROM users " &_
"WHERE user_username='" & username & "' " &_
"AND user_password='" & password & "'"
SET rst = Con.Execute( sqlString )
IF rst.EOF THEN
checkpassword = - 1
ELSE
checkpassword = rst( "user_id" )
addCookie "username", username
addCookie "password", password
END IF
END FUNCTION
SUB errorForm( errorMSG, backpage )
%>
<html>
<head><title>Problem</title></head>
<body bgcolor="lightyellow">
<center>
<table width="500" border=1
cellpadding=5 cellspacing=0>
<tr>
<td>
<font face="Arial" size="3" color="darkblue"><b>
There was a problem with the information you entered:
</b></font>
<font size="2" color="red"><b>
<br><%=errorMSG%>
</b></font>
<br>
<form method="post" action="<%=backpage%>">
<input name="error" type="hidden" value="1">
<% formFields %>
<input type="submit" value="Return">
</form>
</td>
</tr>
</table>
</center>
</body>
</html>
<%
Response.End
END SUB
SUB formFields
FOR each item in Request.Form
%>
<input name="<%=item%>" type="hidden"
value="<%=Server.HTMLEncode( Request( item ) )%>">
<%
NEXT
END SUB
'===========================
' Registration Functions
'===========================
SUB addUser
' Get Registration Fields
newusername = TRIM( Request( "newusername" ) )
newpassword = TRIM( Request( "newpassword" ) )
email = TRIM( Request( "email" ) )
address = TRIM( Request( "address" ) )
ccnumber = TRIM( Request( "ccnumber" ) )
ccexpires = TRIM( Request( "ccexpires" ) )
ccname = TRIM( Request( "ccname" ) )
' Check For Required Fields
backpage = Request.ServerVariables( "SCRIPT_NAME" )
IF newusername = "" THEN
errorForm "You must enter a username.", backpage
END IF
IF newpassword = "" THEN
errorForm "You must enter a password.", backpage
END IF
IF email = "" THEN
errorForm "You must enter your email address.", backpage
END IF
IF address = "" THEN
errorForm "You must enter your address.", backpage
END IF
IF ccnumber = "" THEN
errorForm "You must enter your credit card number.", backpage
END IF
IF ccexpires = "" THEN
errorForm "You must enter your credit card expiry date.", backpage
END IF
IF ccname = "" THEN
errorForm "You must enter the name that appears on your credit card.",
backpage
END IF
' Check for Necessary Field Values
IF invalidEmail( email ) THEN
errorForm "You did not enter a valid email address", backpage
END IF
IF NOT validCCNumber( ccnumber ) THEN
errorForm "You did not enter a valid credit card number", backpage
END IF
IF NOT isDATE( ccexpires ) THEN
errorForm "You did not enter a valid credit card expiration date",
backpage
END IF
' Check whether username already registered
IF alreadyUser( newusername ) THEN
errorForm "Please choose a different username.", backpage
END IF
' Add New User to Database
sqlString = "INSERT INTO users ( " &_
"user_username, " &_
"user_password, " &_
"user_email," &_
"user_add, " &_
"user_ccnumber, " &_
"user_ccexpires," &_
"user_ccname" &_
") VALUES ( " &_
" '" & fixQuotes( newusername ) & "', " &_
" '" & fixQuotes( newpassword ) & "', " &_
" '" & fixQuotes( email ) & "', " &_
" '" & fixQuotes( address ) & "', " &_
" '" & fixQuotes( ccnumber ) & "', " &_
" '" & ccexpires & "', " &_
" '" & fixQuotes( ccname ) & "' " &_
")"
Con.Execute sqlString
' Use the new username and password
username = newusername
password = newpassword
' Add Cookies
addCookie "username", username
addCookie "password", password
END SUB
SUB updateUser
' Get Registration Fields
address = TRIM( Request( "address" ) )
ccnumber = TRIM( Request( "ccnumber" ) )
ccexpires = TRIM( Request( "ccexpires" ) )
ccname = TRIM( Request( "ccname" ) )
' Check For Required Fields
backpage = "checkout.asp"
IF address = "" THEN
errorForm "You must enter your address.", backpage
END IF
IF ccnumber = "" THEN
errorForm "You must enter your credit card number.", backpage
END IF
IF ccexpires = "" THEN
errorForm "You must enter your credit card expiration date.", backpage
END IF
IF ccname = "" THEN
errorForm "You must enter the name that appears on your credit card.",
backpage
END IF
' Check for Necessary Field Values
IF INSTR( ccnumber, "*" ) = 0 THEN
IF NOT validCCNumber( ccnumber ) THEN
errorForm "You did not enter a valid credit card number", backpage
END IF
END IF
IF NOT isDATE( ccexpires ) THEN
errorForm "You did not enter a valid credit card expiration date",
backpage
END IF
' Update user information in the database
sqlString = "UPDATE users SET " &_
"user_add='" & fixQuotes( address ) & "', " &_
"user_ccnumber='" & ccnumber & "', " &_
"user_ccexpires='" & ccexpires & "'," &_
"user_ccname='" & fixQuotes( ccname ) & "' " &_
"WHERE user_id=" & userID
Con.Execute sqlString
END SUB
FUNCTION invalidEmail( email )
IF INSTR( email, "@" ) = 0 OR INSTR( email, "." ) = 0 THEN
invalidEmail = TRUE
ELSE
invalidEmail = FALSE
END IF
END FUNCTION
FUNCTION validCCNumber( ccnumber )
ccnumber = CleanCCNum( ccnumber )
IF ccnumber = "" THEN
validCCNumber = FALSE
ELSE
isEven = False
digits = ""
for i = Len( ccnumber ) To 1 Step -1
if isEven Then
digits = digits & CINT( MID( ccnumber, i, 1) ) * 2
Else
digits = digits & CINT( MID( ccnumber, i, 1) )
End If
isEven = (Not isEven)
Next
checkSum = 0
For i = 1 To Len( digits) Step 1
checkSum = checkSum + CINT( MID( digits, i, 1 ) )
Next
validCCNumber = ( ( checkSum Mod 10) = 0 )
END IF
End Function
FUNCTION alreadyUser( theUsername )
sqlString = "SELECT user_username FROM users " &_
"WHERE user_username='" & fixQuotes( theUsername ) & "'"
SET rst = Con.Execute( sqlString )
IF rst.EOF THEN
alreadyUser = FALSE
ELSE
alreadyUser = TRUE
END IF
rst.Close
END FUNCTION
FUNCTION CleanCCNum( ccnumber )
FOR i = 1 TO LEN( ccnumber )
IF isNumeric( MID( ccnumber, i, 1 ) ) THEN
CleanCCNum = CleanCCNum & MID( ccnumber, i, 1 )
END IF
NEXT
END FUNCTION
%>
register.asp:
<%
newusername = TRIM( Request( "newusername" ) )
newpassword = TRIM( Request( "newpassword" ) )
email = TRIM( Request( "email" ) )
address = TRIM( Request( "address" ) )
cctype = Request( "cctype" )
ccnumber = TRIM( Request( "ccnumber" ) )
ccexpires = TRIM( Request( "ccexpires" ) )
ccname = TRIM( Request( "ccname" ) )
submitpage = Request.ServerVariables( "SCRIPT_NAME" )
%>
<html>
<head><title>Register</title></head>
<body bgcolor="white">
<center>
<table width="500" border=0
cellpadding=4 cellspacing=0>
<tr>
<td bgcolor="darkgreen">
<font color="white" face="Arial">
<b>Login</b>
</font>
</td>
</tr>
<tr>
<td>
<form method="post" action="<%=submitpage%>">
<input name="login" type="hidden" value="1">
<input name="carid" type="hidden" value="<%=carID%>">
<font face="Arial" size="2">
Please enter your username and password:
</font>
<font face="Courier" size="2">
<p><b>username:</b>
<input name="username" size="20"></b>
<br><b>password:</b>
<input name="password" size="20"></b>
<input type="submit" value="Login">
</font>
</form>
</td>
</tr>
<tr>
<td bgcolor="darkgreen">
<font color="white" face="Arial">
<b>Register</b>
</font>
</td>
</tr>
<tr>
<td>
<form method="post" action="<%=submitpage%>">
<input name="register" type="hidden" value="1">
<input name="carid" type="hidden" value="<%=carID%>">
<font face="Arial" size="2">
If you are a new user, please register by completing the following form:
</font>
<font face="Arial" size="2" color="darkgreen">
<p><b>Login Information:</b>
</font>
<font face="Courier" size="2">
<br><b>username:</b>
<input name="newusername" size=20 maxlength
value="<%=Server.HTMLEncode( newusername )%>">
<br><b>password:</b>
<input name="newpassword" size=20 maxlength
value="<%=server.HTMLEncode( newpassword )%>">
<br><b>email address:</b>
<input name="email" size=30 maxlength=75
value="<%=Server.HTMLEncode( email )%>">
</font>
<font face="Arial" size="2" color="darkgreen">
<p><b>Address Information:</b>
</font>
<font face="Courier" size="2">
<br><b>address:</b>
<input name="address" size=20 maxlength=50
value="<%=Server.HTMLEncode( address )%>">
<br>
</font>
<font face="Arial" size="2" color="darkgreen">
<p><b>Payment Information:</b>
</font>
<br><b>credit card number:</b>
<input name="ccnumber" size=20 maxlength
value="<%=Server.HTMLEncode( ccnumber )%>">
<br><b>credit card expires:</b>
<input name="ccexpires" size=20 maxlength
value="<%=Server.HTMLEncode( ccexpires )%>">
<br><b>name on credit card:</b>
<input name="ccname" size=20 maxlength
value="<%=Server.HTMLEncode( ccname )%>">
<input type="submit" value="Register">
</font>
</form>
</td>
</tr>
</table>
</body>
</html>
> In catlist.asp, you open the recordset but forget to close it again -
that's
why you get the error "The operation requested by the application is not
allowed if the object is open." in productlist.asp when you try to open the
recordset, which is already open.
-Kim
> -----Original Message-----
> From: shohokukj@y... [mailto:shohokukj@y...]
> Sent: 15. november 2002 16:42
> To: ASP Databases
> Subject: [asp_databases] RE: question
>
>
> Actually,the whole file is here. Can you please go through it and tell me
> what is wrong? Thanks a lot! I need it urgently.
>
> Default.asp:
>
> <!-- #INCLUDE FILE="adovbs.inc" -->
> <!-- #INCLUDE FILE="opendb.asp" -->
> <%
> ' Get Current Category
> cat = TRIM( Request( "cat" ) )
> IF cat = "" THEN cat = "Home"
>
> %>
> <html>
> <head>
> <title>BestCars</title>
> </head>
> <body link="#ff4040" vtext="lightred" bgcolor="#ffffff">
> <center>
>
> <table width=640 border=0 bgcolor="#ffffff"
> cellspacing=0 cellpadding=0>
> <tr>
> <td>
> <img src="images\bestcar.gif">
> </td>
> <td align=right valign="bottom">
> <a href="cart.asp">shopping cart</a>
> |
> <a href="account.asp">account</a>
> </td>
> </tr>
> <tr>
> <td colspan=2>
> <hr width="640">
> </td>
> </tr>
> </table>
>
>
> <tr>
> <td>
>
> </td>
> </tr>
> <tr align="left">
> <td valign="top">
> <img src="images\Categories.gif" vspace=0 border=0></td>
> </tr>
> <tr>
> <td>
> <table width="200" cellpadding=4 cellspacing=0
> bgcolor="lightyellow" border=1>
> <tr>
> <td>
> <font size="3"><b>
> <!-- #INCLUDE FILE="CatList.asp" -->
> </b></font>
> </td>
> </tr>
> </table>
> </td>
> </tr>
> </table>
>
> </td><td valign="top">
> <% IF cat = "Home" THEN %>
>
> <% ELSE %>
> <!-- #INCLUDE FILE="ProductList.asp" -->
> <% END IF %>
>
> </td></tr>
> </table>
>
> <!-- #INCLUDE FILE="closedb.asp" -->
>
> <hr width=640>
> <H5>Copyright © 2002 BestCars.com. All Rights Reserved<br>
> All information contained here in applies to Singapore Vehicles
> Only<br></H5>
>
>
> </center>
> </body>
> </hmtl>
>
> Productlist.asp:
>
> <%
> strsql = "SELECT car_id, model, car_pic, price " &_
> "FROM spec WHERE car_cat='" & cat & "' " &_
> "ORDER BY model "
> rst.open strsql,con,1,3
>
> %>
> <table width="350" border=0
> cellpadding=5 cellspacing=0>
> <%
> WHILE NOT rst.EOF
> %>
> <tr>
> <td>
> <% IF rst( "car_pic" ) <> "?????" THEN %>
> <IMG SRC="<%=rst( "car_pic" )%>"
> HSPACE=4 VSPACE=4 BORDER=0 align="center">
> <% END IF %>
> </td>
> <td>
> <%=rst( "car_id" )%>
> <b><%=rst( "model" )%></b></a>
> <br><%=rst( "price" )%>
> <form method="post" action="cart.asp">
> <input name="carid" type="hidden" value="<%=rst( "car_id" )%>">
> <input type="submit" value="Add To Cart">
> </form>
> </td>
> </tr>
> <tr>
> <td colspan=2 align="center">
>
> </td>
> </tr>
> <%
> rst.MoveNext
> WEND
> rst.close
> %>
> </table>
>
> Catlist.asp:
>
> <%
> strsql="select DISTINCT car_cat from spec"
> rst.open strsql,con,1,3
> %>
> <% If cat = "Home" THEN %>
> <font color="red"><b>Home</b></font>
> <UL>
> <% ELSE %>
> <a href="default.asp?cat=Home">Home</a>
> <UL>
> <% END IF %>
> <% WHILE NOT rst.EOF %>
> <% IF rst( "car_cat" ) = cat THEN %>
> <li><font color="red"><b>
> <%=rst( "car_cat" )%>
> </b></font>
> <% ELSE %>
> <li><a href="default.asp?cat=<%=Server.URLEncode( rst( "car_cat" ) )%
>"><%
> =rst( "car_cat" )%></a>
> <% END IF %>
> <%
> rst.MoveNext
> WEND
> %>
> </UL>
>
> opendb.asp:
>
> <%
> dim con,rst
> set con = server.createobject("ADODB.Connection")
> set rst = server.createobject("ADODB.Recordset")
> con.open "Driver={Microsoft Access Driver (*.mdb)};Dbq=" & Server.MapPath
> ("cars.mdb")
> %>
>
> Closedb.asp:
>
> <%
> set rst = nothing
> set con = nothing
> %>
>
>
>
>
>
> > There must be more code than that - where do you instantiate
> rst? You're
> probably both instantiating and opening it elsewhere, but forget to close
> it.
>
> -Kim
Message #7 by shohokukj@y... on Sat, 16 Nov 2002 07:04:39
|
|
Is it possible for me to get your email add or icq number so it will be
easier to communicate with you?
> Sorry to trouble you again but can you help me see the add to cart
portion?
T> hanks!!
> cart.asp:
> <!-- #INCLUDE FILE="adovbs.inc" -->
<> !-- #INCLUDE FILE="storefuncs.asp" -->
<> %
'> Get Product ID
p> roductID = TRIM( Request( "pid" ) )
> ' Get Login Information
u> sername = TRIM( Request( "username" ) )
p> assword = TRIM( Request( "password" ) )
r> egister = TRIM( Request( "register" ) )
e> rror = TRIM( Request( "error" ) )
>
'> Check For New Registration
I> F register <> "" AND error = "" THEN
> addUser
E> ND IF
> ' Get User ID
u> serID = checkpassword( username, password, Con )
> IF userID > 0 THEN
> %>
> <!-- #INCLUDE FILE="addCart.asp" -->
> <% ELSE %>
> <!-- #INCLUDE FILE="register.asp" -->
> <%
E> ND IF
%> >
> addCart.asp:
> <!-- #INCLUDE FILE="adovbs.inc" -->
<> !-- #INCLUDE FILE="storefuncs.asp" -->
<> %
'> Get Product ID
p> roductID = TRIM( Request( "pid" ) )
> ' Get Login Information
u> sername = TRIM( Request( "username" ) )
p> assword = TRIM( Request( "password" ) )
r> egister = TRIM( Request( "register" ) )
e> rror = TRIM( Request( "error" ) )
>
'> Check For New Registration
I> F register <> "" AND error = "" THEN
> addUser
E> ND IF
> ' Get User ID
u> serID = checkpassword( username, password, Con )
> IF userID > 0 THEN
> %>
> <!-- #INCLUDE FILE="addCart.asp" -->
> <% ELSE %>
> <!-- #INCLUDE FILE="register.asp" -->
> <%
E> ND IF
%> >
>
s> torefuncs.asp:
> <%
D> im Con
'> ==========================
'> Common Functions
'> ==========================
F> UNCTION fixQuotes( theString )
> fixQuotes = REPLACE( theString, "'", "''" )
E> ND FUNCTION
>
S> UB addCookie( theName, theValue )
> Response.Cookies( theName ) = theValue
> Response.Cookies( theName ).Expires = "Nov 30, 2003"
> Response.Cookies( theName ).Path = "/"
> Response.Cookies( theName ).Secure = FALSE
E> ND SUB
>
> FUNCTION checkpassword( byVal username, byVal password, byRef Con )
> sqlString = "SELECT user_id FROM users " &_
> "WHERE user_username='" & username & "' " &_
> "AND user_password='" & password & "'"
> SET rst = Con.Execute( sqlString )
> IF rst.EOF THEN
> checkpassword = - 1
> ELSE
> checkpassword = rst( "user_id" )
> addCookie "username", username
> addCookie "password", password
> END IF
E> ND FUNCTION
>
> SUB errorForm( errorMSG, backpage )
> %>
> <html>
> <head><title>Problem</title></head>
> <body bgcolor="lightyellow">
> <center>
> <table width="500" border=1
> cellpadding=5 cellspacing=0>
> <tr>
> <td>
> <font face="Arial" size="3" color="darkblue"><b>
> There was a problem with the information you entered:
> </b></font>
> <font size="2" color="red"><b>
> <br><%=errorMSG%>
> </b></font>
> <br>
> <form method="post" action="<%=backpage%>">
> <input name="error" type="hidden" value="1">
> <% formFields %>
> <input type="submit" value="Return">
> </form>
> </td>
> </tr>
> </table>
> </center>
> </body>
> </html>
> <%
> Response.End
E> ND SUB
>
S> UB formFields
> FOR each item in Request.Form
> %>
> <input name="<%=item%>" type="hidden"
> value="<%=Server.HTMLEncode( Request( item ) )%>">
> <%
> NEXT
E> ND SUB
> '===========================
'> Registration Functions
'> ===========================
>
S> UB addUser
> ' Get Registration Fields
> newusername = TRIM( Request( "newusername" ) )
> newpassword = TRIM( Request( "newpassword" ) )
> email = TRIM( Request( "email" ) )
> address = TRIM( Request( "address" ) )
> ccnumber = TRIM( Request( "ccnumber" ) )
> ccexpires = TRIM( Request( "ccexpires" ) )
> ccname = TRIM( Request( "ccname" ) )
> ' Check For Required Fields
> backpage = Request.ServerVariables( "SCRIPT_NAME" )
> IF newusername = "" THEN
> errorForm "You must enter a username.", backpage
> END IF
> IF newpassword = "" THEN
> errorForm "You must enter a password.", backpage
> END IF
> IF email = "" THEN
> errorForm "You must enter your email address.", backpage
> END IF
> IF address = "" THEN
> errorForm "You must enter your address.", backpage
> END IF
> IF ccnumber = "" THEN
> errorForm "You must enter your credit card number.", backpage
> END IF
> IF ccexpires = "" THEN
> errorForm "You must enter your credit card expiry date.", backpage
> END IF
> IF ccname = "" THEN
> errorForm "You must enter the name that appears on your credit
card.",
b> ackpage
> END IF
> ' Check for Necessary Field Values
> IF invalidEmail( email ) THEN
> errorForm "You did not enter a valid email address", backpage
> END IF
> IF NOT validCCNumber( ccnumber ) THEN
> errorForm "You did not enter a valid credit card number", backpage
> END IF
> IF NOT isDATE( ccexpires ) THEN
> errorForm "You did not enter a valid credit card expiration date",
b> ackpage
> END IF
> ' Check whether username already registered
> IF alreadyUser( newusername ) THEN
> errorForm "Please choose a different username.", backpage
> END IF
> ' Add New User to Database
> sqlString = "INSERT INTO users ( " &_
> "user_username, " &_
> "user_password, " &_
> "user_email," &_
> "user_add, " &_
> "user_ccnumber, " &_
> "user_ccexpires," &_
> "user_ccname" &_
> ") VALUES ( " &_
> " '" & fixQuotes( newusername ) & "', " &_
> " '" & fixQuotes( newpassword ) & "', " &_
> " '" & fixQuotes( email ) & "', " &_
> " '" & fixQuotes( address ) & "', " &_
> " '" & fixQuotes( ccnumber ) & "', " &_
> " '" & ccexpires & "', " &_
> " '" & fixQuotes( ccname ) & "' " &_
> ")"
> Con.Execute sqlString
> ' Use the new username and password
> username = newusername
> password = newpassword
> ' Add Cookies
> addCookie "username", username
> addCookie "password", password
E> ND SUB
>
S> UB updateUser
> ' Get Registration Fields
> address = TRIM( Request( "address" ) )
> ccnumber = TRIM( Request( "ccnumber" ) )
> ccexpires = TRIM( Request( "ccexpires" ) )
> ccname = TRIM( Request( "ccname" ) )
> ' Check For Required Fields
> backpage = "checkout.asp"
> IF address = "" THEN
> errorForm "You must enter your address.", backpage
> END IF
> IF ccnumber = "" THEN
> errorForm "You must enter your credit card number.", backpage
> END IF
> IF ccexpires = "" THEN
> errorForm "You must enter your credit card expiration date.",
backpage
> END IF
> IF ccname = "" THEN
> errorForm "You must enter the name that appears on your credit
card.",
b> ackpage
> END IF
> ' Check for Necessary Field Values
> IF INSTR( ccnumber, "*" ) = 0 THEN
> IF NOT validCCNumber( ccnumber ) THEN
> errorForm "You did not enter a valid credit card number", backpage
> END IF
> END IF
> IF NOT isDATE( ccexpires ) THEN
> errorForm "You did not enter a valid credit card expiration date",
b> ackpage
> END IF
> ' Update user information in the database
> sqlString = "UPDATE users SET " &_
> "user_add='" & fixQuotes( address ) & "', " &_
> "user_ccnumber='" & ccnumber & "', " &_
> "user_ccexpires='" & ccexpires & "'," &_
> "user_ccname='" & fixQuotes( ccname ) & "' " &_
> "WHERE user_id=" & userID
> Con.Execute sqlString
E> ND SUB
>
> FUNCTION invalidEmail( email )
> IF INSTR( email, "@" ) = 0 OR INSTR( email, "." ) = 0 THEN
> invalidEmail = TRUE
> ELSE
> invalidEmail = FALSE
> END IF
E> ND FUNCTION
> FUNCTION validCCNumber( ccnumber )
> ccnumber = CleanCCNum( ccnumber )
> IF ccnumber = "" THEN
> validCCNumber = FALSE
> ELSE
> isEven = False
> digits = ""
> for i = Len( ccnumber ) To 1 Step -1
> if isEven Then
> digits = digits & CINT( MID( ccnumber, i, 1) ) * 2
> Else
> digits = digits & CINT( MID( ccnumber, i, 1) )
> End If
> isEven = (Not isEven)
> Next
> checkSum = 0
> For i = 1 To Len( digits) Step 1
> checkSum = checkSum + CINT( MID( digits, i, 1 ) )
> Next
> validCCNumber = ( ( checkSum Mod 10) = 0 )
> END IF
E> nd Function
> FUNCTION alreadyUser( theUsername )
> sqlString = "SELECT user_username FROM users " &_
> "WHERE user_username='" & fixQuotes( theUsername ) & "'"
> SET rst = Con.Execute( sqlString )
> IF rst.EOF THEN
> alreadyUser = FALSE
> ELSE
> alreadyUser = TRUE
> END IF
> rst.Close
E> ND FUNCTION
>
> FUNCTION CleanCCNum( ccnumber )
> FOR i = 1 TO LEN( ccnumber )
> IF isNumeric( MID( ccnumber, i, 1 ) ) THEN
> CleanCCNum = CleanCCNum & MID( ccnumber, i, 1 )
> END IF
> NEXT
E> ND FUNCTION
>
%> >
> register.asp:
> <%
n> ewusername = TRIM( Request( "newusername" ) )
n> ewpassword = TRIM( Request( "newpassword" ) )
e> mail = TRIM( Request( "email" ) )
a> ddress = TRIM( Request( "address" ) )
c> ctype = Request( "cctype" )
c> cnumber = TRIM( Request( "ccnumber" ) )
c> cexpires = TRIM( Request( "ccexpires" ) )
c> cname = TRIM( Request( "ccname" ) )
> submitpage = Request.ServerVariables( "SCRIPT_NAME" )
%> >
> <html>
<> head><title>Register</title></head>
<> body bgcolor="white">
> <center>
<> table width="500" border=0
> cellpadding=4 cellspacing=0>
<> tr>
> <td bgcolor="darkgreen">
> <font color="white" face="Arial">
> <b>Login</b>
> </font>
> </td>
<> /tr>
<> tr>
> <td>
> <form method="post" action="<%=submitpage%>">
> <input name="login" type="hidden" value="1">
> <input name="carid" type="hidden" value="<%=carID%>">
> <font face="Arial" size="2">
> Please enter your username and password:
> </font>
> <font face="Courier" size="2">
> <p><b>username:</b>
> <input name="username" size="20"></b>
> <br><b>password:</b>
> <input name="password" size="20"></b>
> <input type="submit" value="Login">
> </font>
> </form>
> </td>
<> /tr>
<> tr>
> <td bgcolor="darkgreen">
> <font color="white" face="Arial">
> <b>Register</b>
> </font>
> </td>
<> /tr>
<> tr>
> <td>
>
> <form method="post" action="<%=submitpage%>">
> <input name="register" type="hidden" value="1">
> <input name="carid" type="hidden" value="<%=carID%>">
> <font face="Arial" size="2">
> If you are a new user, please register by completing the following
form:
> </font>
> <font face="Arial" size="2" color="darkgreen">
> <p><b>Login Information:</b>
> </font>
> <font face="Courier" size="2">
> <br><b>username:</b>
> <input name="newusername" size=20 maxlength
> value="<%=Server.HTMLEncode( newusername )%>">
> <br><b>password:</b>
> <input name="newpassword" size=20 maxlength
> value="<%=server.HTMLEncode( newpassword )%>">
> <br><b>email address:</b>
> <input name="email" size=30 maxlength=75
> value="<%=Server.HTMLEncode( email )%>">
> </font>
> <font face="Arial" size="2" color="darkgreen">
> <p><b>Address Information:</b>
> </font>
> <font face="Courier" size="2">
> <br><b>address:</b>
> <input name="address" size=20 maxlength=50
> value="<%=Server.HTMLEncode( address )%>">
> <br>
> </font>
> <font face="Arial" size="2" color="darkgreen">
> <p><b>Payment Information:</b>
> </font>
> <br><b>credit card number:</b>
> <input name="ccnumber" size=20 maxlength
> value="<%=Server.HTMLEncode( ccnumber )%>">
> <br><b>credit card expires:</b>
> <input name="ccexpires" size=20 maxlength
> value="<%=Server.HTMLEncode( ccexpires )%>">
> <br><b>name on credit card:</b>
> <input name="ccname" size=20 maxlength
> value="<%=Server.HTMLEncode( ccname )%>">
> <input type="submit" value="Register">
> </font>
> </form>
> </td>
<> /tr>
<> /table>
> </body>
<> /html>
>
>
> > In catlist.asp, you open the recordset but forget to close it again -
t> hat's
w> hy you get the error "The operation requested by the application is not
a> llowed if the object is open." in productlist.asp when you try to open
the
r> ecordset, which is already open.
> -Kim
>
>> -----Original Message-----
>> From: shohokukj@y... [mailto:shohokukj@y...]
>> Sent: 15. november 2002 16:42
>> To: ASP Databases
>> Subject: [asp_databases] RE: question
>>
>>
>> Actually,the whole file is here. Can you please go through it and tell
me
>> what is wrong? Thanks a lot! I need it urgently.
>>
>> Default.asp:
>>
>> <!-- #INCLUDE FILE="adovbs.inc" -->
>> <!-- #INCLUDE FILE="opendb.asp" -->
>> <%
>> ' Get Current Category
>> cat = TRIM( Request( "cat" ) )
>> IF cat = "" THEN cat = "Home"
>>
>> %>
>> <html>
>> <head>
>> <title>BestCars</title>
>> </head>
>> <body link="#ff4040" vtext="lightred" bgcolor="#ffffff">
>> <center>
>>
>> <table width=640 border=0 bgcolor="#ffffff"
>> cellspacing=0 cellpadding=0>
>> <tr>
>> <td>
>> <img src="images\bestcar.gif">
>> </td>
>> <td align=right valign="bottom">
>> <a href="cart.asp">shopping cart</a>
>> |
>> <a href="account.asp">account</a>
>> </td>
>> </tr>
>> <tr>
>> <td colspan=2>
>> <hr width="640">
>> </td>
>> </tr>
>> </table>
>>
>>
>> <tr>
>> <td>
>>
>> </td>
>> </tr>
>> <tr align="left">
>> <td valign="top">
>> <img src="images\Categories.gif" vspace=0 border=0></td>
>> </tr>
>> <tr>
>> <td>
>> <table width="200" cellpadding=4 cellspacing=0
>> bgcolor="lightyellow" border=1>
>> <tr>
>> <td>
>> <font size="3"><b>
>> <!-- #INCLUDE FILE="CatList.asp" -->
>> </b></font>
>> </td>
>> </tr>
>> </table>
>> </td>
>> </tr>
>> </table>
>>
>> </td><td valign="top">
>> <% IF cat = "Home" THEN %>
>>
>> <% ELSE %>
>> <!-- #INCLUDE FILE="ProductList.asp" -->
>> <% END IF %>
>>
>> </td></tr>
>> </table>
>>
>> <!-- #INCLUDE FILE="closedb.asp" -->
>>
>> <hr width=640>
>> <H5>Copyright © 2002 BestCars.com. All Rights Reserved<br>
>> All information contained here in applies to Singapore Vehicles
>> Only<br></H5>
>>
>>
>> </center>
>> </body>
>> </hmtl>
>>
>> Productlist.asp:
>>
>> <%
>> strsql = "SELECT car_id, model, car_pic, price " &_
>> "FROM spec WHERE car_cat='" & cat & "' " &_
>> "ORDER BY model "
>> rst.open strsql,con,1,3
>>
>> %>
>> <table width="350" border=0
>> cellpadding=5 cellspacing=0>
>> <%
>> WHILE NOT rst.EOF
>> %>
>> <tr>
>> <td>
>> <% IF rst( "car_pic" ) <> "?????" THEN %>
>> <IMG SRC="<%=rst( "car_pic" )%>"
>> HSPACE=4 VSPACE=4 BORDER=0 align="center">
>> <% END IF %>
>> </td>
>> <td>
>> <%=rst( "car_id" )%>
>> <b><%=rst( "model" )%></b></a>
>> <br><%=rst( "price" )%>
>> <form method="post" action="cart.asp">
>> <input name="carid" type="hidden" value="<%=rst( "car_id" )%>">
>> <input type="submit" value="Add To Cart">
>> </form>
>> </td>
>> </tr>
>> <tr>
>> <td colspan=2 align="center">
>>
>> </td>
>> </tr>
>> <%
>> rst.MoveNext
>> WEND
>> rst.close
>> %>
>> </table>
>>
>> Catlist.asp:
>>
>> <%
>> strsql="select DISTINCT car_cat from spec"
>> rst.open strsql,con,1,3
>> %>
>> <% If cat = "Home" THEN %>
>> <font color="red"><b>Home</b></font>
>> <UL>
>> <% ELSE %>
>> <a href="default.asp?cat=Home">Home</a>
>> <UL>
>> <% END IF %>
>> <% WHILE NOT rst.EOF %>
>> <% IF rst( "car_cat" ) = cat THEN %>
>> <li><font color="red"><b>
>> <%=rst( "car_cat" )%>
>> </b></font>
>> <% ELSE %>
>> <li><a href="default.asp?cat=<%=Server.URLEncode( rst( "car_cat" ) )%
>> "><%
>> =rst( "car_cat" )%></a>
>> <% END IF %>
>> <%
>> rst.MoveNext
>> WEND
>> %>
>> </UL>
>>
>> opendb.asp:
>>
>> <%
>> dim con,rst
>> set con = server.createobject("ADODB.Connection")
>> set rst = server.createobject("ADODB.Recordset")
>> con.open "Driver={Microsoft Access Driver (*.mdb)};Dbq=" &
Server.MapPath
>> ("cars.mdb")
>> %>
>>
>> Closedb.asp:
>>
>> <%
>> set rst = nothing
>> set con = nothing
>> %>
>>
>>
>>
>>
>>
>> > There must be more code than that - where do you instantiate
>> rst? You're
>> probably both instantiating and opening it elsewhere, but forget to
close
>> it.
>>
>> -Kim
>
Message #8 by shohokukj@y... on Sat, 16 Nov 2002 08:12:31
|
|
Sorry. Please ignore the previous message. Here's the real file. Just now
was a mistake. Please help me correct them as I need them urgently.
Thanks!!!!
Here are the files
cart.asp:
<!-- #INCLUDE FILE="adovbs.inc" -->
<!-- #INCLUDE FILE="storefuncs.asp" -->
<!-- #INCLUDE FILE="opendb.asp" -->
<%
' 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" ) )
' Check For New Registration
IF register <> "" AND error = "" THEN
addUser
END IF
' Get User ID
userID = checkpassword( username, password, Con )
IF userID > 0 THEN
%>
<!-- #INCLUDE FILE="addCart.asp" -->
<% ELSE %>
<!-- #INCLUDE FILE="register.asp" -->
<%
END IF
%>
<!-- #INCLUDE FILE="closedb.asp" -->
AddCart.asp:
<%
' Get Product ID
carID = TRIM( Request( "car_id" ) )
' Add Item to cart
IF carID <> "" THEN
sqlString = "SELECT cart_id FROM cart " &_
"WHERE cart_userID=" & userID & " " &_
"AND cart_carID=" & carID
SET rst = Con.Execute( sqlString )
IF rst.EOF THEN
sqlString = "INSERT INTO cart ( " &_
"cart_userID, " &_
"cart_carID, " &_
"cart_quantity " &_
") VALUES ( " &_
userID & ", " &_
carID & ", 1 )"
ELSE
sqlString = "UPDATE cart SET " &_
"cart_quantity=cart_quantity+1 " &_
"WHERE cart_id=" & rst( "cart_id" )
END IF
rst.Close
SET rst = Nothing
Con.Execute sqlString
END IF
' Update Shopping Cart Quantities
IF Request( "updateQ" ) <> "" THEN
SET rst = Server.CreateObject( "ADODB.Recordset" )
rst.ActiveConnection = Con
rst.CursorType = adOpenDynamic
rst.LockType = adLockOptimistic
sqlString = "SELECT cart_id, cart_quantity FROM cart " &_
"WHERE cart_userID=" & userID
rst.Open sqlString
WHILE NOT rst.EOF
newQ = TRIM( Request( "pq" & rst( "cart_id" ) ) )
IF newQ = "" OR newQ = "0" THEN
rst.Delete
ELSE
IF isNumeric( newQ ) THEN
rst( "cart_quantity" ) = newQ
END IF
END IF
rst.MoveNext
WEND
rst.Close
SET rst = Nothing
END IF
%>
<html>
<head><title>Shopping Cart</title></head>
<body bgcolor="white">
<center>
<font face="Arial" size=3 color="darkgreen">
<b><%=username%>'s shopping cart:</b>
</font>
<%
' Get the shopping cart
sqlString = "SELECT cart_id, model, " &_
"price, cart_quantity " &_
"FROM cart, spec " &_
"WHERE cart_userID=" & userID & " " &_
"AND cart_carID = car_id " &_
"ORDER BY cart_id DESC"
SET rst = Con.Execute( sqlString )
IF rst.EOF THEN
%>
<p><b>You do not have any items in your shopping cart</b>
<p>
<form action="default.asp">
<input type="submit" value="Continue Shopping">
</form>
<%
ELSE
orderTotal = 0
%>
<form method="post" action="cart.asp">
<input name="updateQ" type="hidden" value="1">
<input name="username" type="hidden" value="<%=username%>">
<input name="password" type="hidden" value="<%=password%>">
<table bgcolor="lightyellow" border=1
cellpadding=4 cellspacing=0>
<tr bgcolor="lightgreen">
<th>Product</th>
<th>Price</th>
<th>Quantity</th>
</tr>
<%
WHILE NOT rst.EOF
orderTotal = orderTotal + ( rst( "price" ) * rst( "cart_quantity" ) )
%>
<tr>
<td>
<%=Server.HTMLEncode( rst( "model" ) )%>
</td>
<td>
<%=formatCurrency( rst( "price" ) )%>
</td>
<td>
<input name="pq<%=rst( "cart_id" )%>" type="text" size=4
value="<%=rst( "cart_quantity" )%>">
</td>
</tr>
<%
rst.MoveNext
WEND
%>
<tr bgcolor="yellow">
<td colspan=2 align=right>
<b>Order Total:</b>
</td>
<td>
<%=formatCurrency( orderTotal )%>
</td>
</tr>
<tr>
<td colspan=3>
<table border=0>
<tr>
<td align="right">
<input type="submit" value="Update Cart">
</td>
</form>
<form method="post" action="checkout.asp">
<input name="username" type="hidden" value="<%=username%>">
<input name="password" type="hidden" value="<%=password%>">
<td>
<input type="submit" value="Checkout">
</td>
</form>
<form action="default.asp">
<td>
<input type="submit" value="Continue Shopping">
</td>
</form>
</tr>
</table>
</td>
</tr>
</table>
<% END IF %>
</center>
</body>
</html>
storefuncs.asp:
<%
'==========================
' Common Functions
'==========================
FUNCTION fixQuotes( theString )
fixQuotes = REPLACE( theString, "'", "''" )
END FUNCTION
SUB addCookie( theName, theValue )
Response.Cookies( theName ) = theValue
Response.Cookies( theName ).Expires = "Nov 30, 2003"
Response.Cookies( theName ).Path = "/"
Response.Cookies( theName ).Secure = FALSE
END SUB
FUNCTION checkpassword( byVal username, byVal password, byRef Con )
sqlString = "SELECT user_id FROM users " &_
"WHERE user_username='" & username & "' " &_
"AND user_password='" & password & "'"
SET rst = Con.Execute( sqlString )
IF rst.EOF THEN
checkpassword = - 1
ELSE
checkpassword = rst( "user_id" )
addCookie "username", username
addCookie "password", password
END IF
END FUNCTION
SUB errorForm( errorMSG, backpage )
%>
<html>
<head><title>Problem</title></head>
<body bgcolor="lightyellow">
<center>
<table width="500" border=1
cellpadding=5 cellspacing=0>
<tr>
<td>
<font face="Arial" size="3" color="darkblue"><b>
There was a problem with the information you entered:
</b></font>
<font size="2" color="red"><b>
<br><%=errorMSG%>
</b></font>
<br>
<form method="post" action="<%=backpage%>">
<input name="error" type="hidden" value="1">
<% formFields %>
<input type="submit" value="Return">
</form>
</td>
</tr>
</table>
</center>
</body>
</html>
<%
Response.End
END SUB
SUB formFields
FOR each item in Request.Form
%>
<input name="<%=item%>" type="hidden"
value="<%=Server.HTMLEncode( Request( item ) )%>">
<%
NEXT
END SUB
'===========================
' Registration Functions
'===========================
SUB addUser
' Get Registration Fields
newusername = TRIM( Request( "newusername" ) )
newpassword = TRIM( Request( "newpassword" ) )
email = TRIM( Request( "email" ) )
address = TRIM( Request( "address" ) )
ccnumber = TRIM( Request( "ccnumber" ) )
ccexpires = TRIM( Request( "ccexpires" ) )
ccname = TRIM( Request( "ccname" ) )
' Check For Required Fields
backpage = Request.ServerVariables( "SCRIPT_NAME" )
IF newusername = "" THEN
errorForm "You must enter a username.", backpage
END IF
IF newpassword = "" THEN
errorForm "You must enter a password.", backpage
END IF
IF email = "" THEN
errorForm "You must enter your email address.", backpage
END IF
IF address = "" THEN
errorForm "You must enter your address.", backpage
END IF
IF ccnumber = "" THEN
errorForm "You must enter your credit card number.", backpage
END IF
IF ccexpires = "" THEN
errorForm "You must enter your credit card expiry date.", backpage
END IF
IF ccname = "" THEN
errorForm "You must enter the name that appears on your credit card.",
backpage
END IF
' Check for Necessary Field Values
IF invalidEmail( email ) THEN
errorForm "You did not enter a valid email address", backpage
END IF
IF NOT validCCNumber( ccnumber ) THEN
errorForm "You did not enter a valid credit card number", backpage
END IF
IF NOT isDATE( ccexpires ) THEN
errorForm "You did not enter a valid credit card expiration date",
backpage
END IF
' Check whether username already registered
IF alreadyUser( newusername ) THEN
errorForm "Please choose a different username.", backpage
END IF
' Add New User to Database
sqlString = "INSERT INTO users ( " &_
"user_username, " &_
"user_password, " &_
"user_email," &_
"user_add, " &_
"user_ccnumber, " &_
"user_ccexpires," &_
"user_ccname" &_
") VALUES ( " &_
" '" & fixQuotes( newusername ) & "', " &_
" '" & fixQuotes( newpassword ) & "', " &_
" '" & fixQuotes( email ) & "', " &_
" '" & fixQuotes( address ) & "', " &_
" '" & fixQuotes( ccnumber ) & "', " &_
" '" & ccexpires & "', " &_
" '" & fixQuotes( ccname ) & "' " &_
")"
Con.Execute sqlString
' Use the new username and password
username = newusername
password = newpassword
' Add Cookies
addCookie "username", username
addCookie "password", password
END SUB
SUB updateUser
' Get Registration Fields
address = TRIM( Request( "address" ) )
ccnumber = TRIM( Request( "ccnumber" ) )
ccexpires = TRIM( Request( "ccexpires" ) )
ccname = TRIM( Request( "ccname" ) )
' Check For Required Fields
backpage = "checkout.asp"
IF address = "" THEN
errorForm "You must enter your address.", backpage
END IF
IF ccnumber = "" THEN
errorForm "You must enter your credit card number.", backpage
END IF
IF ccexpires = "" THEN
errorForm "You must enter your credit card expiration date.", backpage
END IF
IF ccname = "" THEN
errorForm "You must enter the name that appears on your credit card.",
backpage
END IF
' Check for Necessary Field Values
IF INSTR( ccnumber, "*" ) = 0 THEN
IF NOT validCCNumber( ccnumber ) THEN
errorForm "You did not enter a valid credit card number", backpage
END IF
END IF
IF NOT isDATE( ccexpires ) THEN
errorForm "You did not enter a valid credit card expiration date",
backpage
END IF
' Update user information in the database
sqlString = "UPDATE users SET " &_
"user_add='" & fixQuotes( address ) & "', " &_
"user_ccnumber='" & ccnumber & "', " &_
"user_ccexpires='" & ccexpires & "'," &_
"user_ccname='" & fixQuotes( ccname ) & "' " &_
"WHERE user_id=" & userID
Con.Execute sqlString
END SUB
FUNCTION invalidEmail( email )
IF INSTR( email, "@" ) = 0 OR INSTR( email, "." ) = 0 THEN
invalidEmail = TRUE
ELSE
invalidEmail = FALSE
END IF
END FUNCTION
FUNCTION validCCNumber( ccnumber )
ccnumber = CleanCCNum( ccnumber )
IF ccnumber = "" THEN
validCCNumber = FALSE
ELSE
isEven = False
digits = ""
for i = Len( ccnumber ) To 1 Step -1
if isEven Then
digits = digits & CINT( MID( ccnumber, i, 1) ) * 2
Else
digits = digits & CINT( MID( ccnumber, i, 1) )
End If
isEven = (Not isEven)
Next
checkSum = 0
For i = 1 To Len( digits) Step 1
checkSum = checkSum + CINT( MID( digits, i, 1 ) )
Next
validCCNumber = ( ( checkSum Mod 10) = 0 )
END IF
End Function
FUNCTION alreadyUser( theUsername )
sqlString = "SELECT user_username FROM users " &_
"WHERE user_username='" & fixQuotes( theUsername ) & "'"
SET rst = Con.Execute( sqlString )
IF rst.EOF THEN
alreadyUser = FALSE
ELSE
alreadyUser = TRUE
END IF
rst.Close
END FUNCTION
FUNCTION CleanCCNum( ccnumber )
FOR i = 1 TO LEN( ccnumber )
IF isNumeric( MID( ccnumber, i, 1 ) ) THEN
CleanCCNum = CleanCCNum & MID( ccnumber, i, 1 )
END IF
NEXT
END FUNCTION
%>
register.asp:
<%
newusername = TRIM( Request( "newusername" ) )
newpassword = TRIM( Request( "newpassword" ) )
email = TRIM( Request( "email" ) )
address = TRIM( Request( "address" ) )
cctype = Request( "cctype" )
ccnumber = TRIM( Request( "ccnumber" ) )
ccexpires = TRIM( Request( "ccexpires" ) )
ccname = TRIM( Request( "ccname" ) )
submitpage = Request.ServerVariables( "SCRIPT_NAME" )
%>
<html>
<head><title>Register</title></head>
<body bgcolor="white">
<center>
<table width="500" border=0
cellpadding=4 cellspacing=0>
<tr>
<td bgcolor="darkgreen">
<font color="white" face="Arial">
<b>Login</b>
</font>
</td>
</tr>
<tr>
<td>
<form method="post" action="<%=submitpage%>">
<input name="login" type="hidden" value="1">
<input name="carid" type="hidden" value="<%=carID%>">
<font face="Arial" size="2">
Please enter your username and password:
</font>
<font face="Courier" size="2">
<p><b>username:</b>
<input name="username" size="20"></b>
<br><b>password:</b>
<input name="password" size="20"></b>
<input type="submit" value="Login">
</font>
</form>
</td>
</tr>
<tr>
<td bgcolor="darkgreen">
<font color="white" face="Arial">
<b>Register</b>
</font>
</td>
</tr>
<tr>
<td>
<form method="post" action="<%=submitpage%>">
<input name="register" type="hidden" value="1">
<input name="carid" type="hidden" value="<%=carID%>">
<font face="Arial" size="2">
If you are a new user, please register by completing the following form:
</font>
<font face="Arial" size="2" color="darkgreen">
<p><b>Login Information:</b>
</font>
<font face="Courier" size="2">
<br><b>username:</b>
<input name="newusername" size=20 maxlength
value="<%=Server.HTMLEncode( newusername )%>">
<br><b>password:</b>
<input name="newpassword" size=20 maxlength
value="<%=server.HTMLEncode( newpassword )%>">
<br><b>email address:</b>
<input name="email" size=30 maxlength=75
value="<%=Server.HTMLEncode( email )%>">
</font>
<font face="Arial" size="2" color="darkgreen">
<p><b>Address Information:</b>
</font>
<font face="Courier" size="2">
<br><b>address:</b>
<input name="address" size=20 maxlength=50
value="<%=Server.HTMLEncode( address )%>">
<br>
</font>
<font face="Arial" size="2" color="darkgreen">
<p><b>Payment Information:</b>
</font>
<br><b>credit card number:</b>
<input name="ccnumber" size=20 maxlength
value="<%=Server.HTMLEncode( ccnumber )%>">
<br><b>credit card expires:</b>
<input name="ccexpires" size=20 maxlength
value="<%=Server.HTMLEncode( ccexpires )%>">
<br><b>name on credit card:</b>
<input name="ccname" size=20 maxlength
value="<%=Server.HTMLEncode( ccname )%>">
<input type="submit" value="Register">
</font>
</form>
</td>
</tr>
</table>
</body>
</html>
Message #9 by shohokukj@y... on Sat, 16 Nov 2002 08:42:01
|
|
why do I always have this error message "Microsoft OLE DB Provider for
ODBC Drivers error '80004005'
[Microsoft][ODBC Microsoft Access Driver] Type mismatch in expression.
/addCart.asp, line 76 "
Can you please help me???
Me really need help desperately.
> Sorry. Please ignore the previous message. Here's the real file. Just
now
w> as a mistake. Please help me correct them as I need them urgently.
T> hanks!!!!
> Here are the files
> cart.asp:
> <!-- #INCLUDE FILE="adovbs.inc" -->
<> !-- #INCLUDE FILE="storefuncs.asp" -->
<> !-- #INCLUDE FILE="opendb.asp" -->
<> %
'> Get Product ID
p> roductID = TRIM( Request( "pid" ) )
> ' Get Login Information
u> sername = TRIM( Request( "username" ) )
p> assword = TRIM( Request( "password" ) )
r> egister = TRIM( Request( "register" ) )
e> rror = TRIM( Request( "error" ) )
>
'> Check For New Registration
I> F register <> "" AND error = "" THEN
> addUser
E> ND IF
> ' Get User ID
u> serID = checkpassword( username, password, Con )
> IF userID > 0 THEN
> %>
> <!-- #INCLUDE FILE="addCart.asp" -->
> <% ELSE %>
> <!-- #INCLUDE FILE="register.asp" -->
> <%
E> ND IF
%> >
<> !-- #INCLUDE FILE="closedb.asp" -->
>
>
A> ddCart.asp:
> <%
'> Get Product ID
c> arID = TRIM( Request( "car_id" ) )
>
'> Add Item to cart
I> F carID <> "" THEN
> sqlString = "SELECT cart_id FROM cart " &_
> "WHERE cart_userID=" & userID & " " &_
> "AND cart_carID=" & carID
> SET rst = Con.Execute( sqlString )
> IF rst.EOF THEN
> sqlString = "INSERT INTO cart ( " &_
> "cart_userID, " &_
> "cart_carID, " &_
> "cart_quantity " &_
> ") VALUES ( " &_
> userID & ", " &_
> carID & ", 1 )"
> ELSE
> sqlString = "UPDATE cart SET " &_
> "cart_quantity=cart_quantity+1 " &_
> "WHERE cart_id=" & rst( "cart_id" )
> END IF
> rst.Close
> SET rst = Nothing
> Con.Execute sqlString
E> ND IF
>
'> Update Shopping Cart Quantities
I> F Request( "updateQ" ) <> "" THEN
S> ET rst = Server.CreateObject( "ADODB.Recordset" )
r> st.ActiveConnection = Con
r> st.CursorType = adOpenDynamic
r> st.LockType = adLockOptimistic
s> qlString = "SELECT cart_id, cart_quantity FROM cart " &_
> "WHERE cart_userID=" & userID
r> st.Open sqlString
W> HILE NOT rst.EOF
n> ewQ = TRIM( Request( "pq" & rst( "cart_id" ) ) )
I> F newQ = "" OR newQ = "0" THEN
> rst.Delete
E> LSE
> IF isNumeric( newQ ) THEN
> rst( "cart_quantity" ) = newQ
> END IF
E> ND IF
r> st.MoveNext
W> END
r> st.Close
S> ET rst = Nothing
E> ND IF
>
>
%> >
<> html>
<> head><title>Shopping Cart</title></head>
<> body bgcolor="white">
> <center>
<> font face="Arial" size=3 color="darkgreen">
<> b><%=username%>'s shopping cart:</b>
<> /font>
> <%
'> Get the shopping cart
s> qlString = "SELECT cart_id, model, " &_
> "price, cart_quantity " &_
> "FROM cart, spec " &_
> "WHERE cart_userID=" & userID & " " &_
> "AND cart_carID = car_id " &_
> "ORDER BY cart_id DESC"
S> ET rst = Con.Execute( sqlString )
> IF rst.EOF THEN
%> >
<> p><b>You do not have any items in your shopping cart</b>
<> p>
<> form action="default.asp">
<> input type="submit" value="Continue Shopping">
<> /form>
<> %
E> LSE
o> rderTotal = 0
%> >
<> form method="post" action="cart.asp">
<> input name="updateQ" type="hidden" value="1">
<> input name="username" type="hidden" value="<%=username%>">
<> input name="password" type="hidden" value="<%=password%>">
<> table bgcolor="lightyellow" border=1
> cellpadding=4 cellspacing=0>
<> tr bgcolor="lightgreen">
> <th>Product</th>
> <th>Price</th>
> <th>Quantity</th>
<> /tr>
<> %
W> HILE NOT rst.EOF
o> rderTotal = orderTotal + ( rst( "price" ) * rst( "cart_quantity" ) )
%> >
<> tr>
> <td>
> <%=Server.HTMLEncode( rst( "model" ) )%>
> </td>
> <td>
> <%=formatCurrency( rst( "price" ) )%>
> </td>
> <td>
> <input name="pq<%=rst( "cart_id" )%>" type="text" size=4
> value="<%=rst( "cart_quantity" )%>">
> </td>
<> /tr>
<> %
r> st.MoveNext
W> END
%> >
<> tr bgcolor="yellow">
> <td colspan=2 align=right>
> <b>Order Total:</b>
> </td>
> <td>
> <%=formatCurrency( orderTotal )%>
> </td>
<> /tr>
<> tr>
> <td colspan=3>
> <table border=0>
> <tr>
> <td align="right">
> <input type="submit" value="Update Cart">
> </td>
> </form>
> <form method="post" action="checkout.asp">
> <input name="username" type="hidden" value="<%=username%>">
> <input name="password" type="hidden" value="<%=password%>">
> <td>
> <input type="submit" value="Checkout">
> </td>
> </form>
> <form action="default.asp">
> <td>
> <input type="submit" value="Continue Shopping">
> </td>
> </form>
> </tr>
> </table>
> </td>
<> /tr>
<> /table>
<> % END IF %>
>
<> /center>
> </body>
<> /html>
>
> storefuncs.asp:
> <%
'> ==========================
'> Common Functions
'> ==========================
F> UNCTION fixQuotes( theString )
> fixQuotes = REPLACE( theString, "'", "''" )
E> ND FUNCTION
>
S> UB addCookie( theName, theValue )
> Response.Cookies( theName ) = theValue
> Response.Cookies( theName ).Expires = "Nov 30, 2003"
> Response.Cookies( theName ).Path = "/"
> Response.Cookies( theName ).Secure = FALSE
E> ND SUB
>
> FUNCTION checkpassword( byVal username, byVal password, byRef Con )
> sqlString = "SELECT user_id FROM users " &_
> "WHERE user_username='" & username & "' " &_
> "AND user_password='" & password & "'"
> SET rst = Con.Execute( sqlString )
> IF rst.EOF THEN
> checkpassword = - 1
> ELSE
> checkpassword = rst( "user_id" )
> addCookie "username", username
> addCookie "password", password
> END IF
E> ND FUNCTION
>
> SUB errorForm( errorMSG, backpage )
> %>
> <html>
> <head><title>Problem</title></head>
> <body bgcolor="lightyellow">
> <center>
> <table width="500" border=1
> cellpadding=5 cellspacing=0>
> <tr>
> <td>
> <font face="Arial" size="3" color="darkblue"><b>
> There was a problem with the information you entered:
> </b></font>
> <font size="2" color="red"><b>
> <br><%=errorMSG%>
> </b></font>
> <br>
> <form method="post" action="<%=backpage%>">
> <input name="error" type="hidden" value="1">
> <% formFields %>
> <input type="submit" value="Return">
> </form>
> </td>
> </tr>
> </table>
> </center>
> </body>
> </html>
> <%
> Response.End
E> ND SUB
>
S> UB formFields
> FOR each item in Request.Form
> %>
> <input name="<%=item%>" type="hidden"
> value="<%=Server.HTMLEncode( Request( item ) )%>">
> <%
> NEXT
E> ND SUB
> '===========================
'> Registration Functions
'> ===========================
>
S> UB addUser
> ' Get Registration Fields
> newusername = TRIM( Request( "newusername" ) )
> newpassword = TRIM( Request( "newpassword" ) )
> email = TRIM( Request( "email" ) )
> address = TRIM( Request( "address" ) )
> ccnumber = TRIM( Request( "ccnumber" ) )
> ccexpires = TRIM( Request( "ccexpires" ) )
> ccname = TRIM( Request( "ccname" ) )
> ' Check For Required Fields
> backpage = Request.ServerVariables( "SCRIPT_NAME" )
> IF newusername = "" THEN
> errorForm "You must enter a username.", backpage
> END IF
> IF newpassword = "" THEN
> errorForm "You must enter a password.", backpage
> END IF
> IF email = "" THEN
> errorForm "You must enter your email address.", backpage
> END IF
> IF address = "" THEN
> errorForm "You must enter your address.", backpage
> END IF
> IF ccnumber = "" THEN
> errorForm "You must enter your credit card number.", backpage
> END IF
> IF ccexpires = "" THEN
> errorForm "You must enter your credit card expiry date.", backpage
> END IF
> IF ccname = "" THEN
> errorForm "You must enter the name that appears on your credit
card.",
b> ackpage
> END IF
> ' Check for Necessary Field Values
> IF invalidEmail( email ) THEN
> errorForm "You did not enter a valid email address", backpage
> END IF
> IF NOT validCCNumber( ccnumber ) THEN
> errorForm "You did not enter a valid credit card number", backpage
> END IF
> IF NOT isDATE( ccexpires ) THEN
> errorForm "You did not enter a valid credit card expiration date",
b> ackpage
> END IF
> ' Check whether username already registered
> IF alreadyUser( newusername ) THEN
> errorForm "Please choose a different username.", backpage
> END IF
> ' Add New User to Database
> sqlString = "INSERT INTO users ( " &_
> "user_username, " &_
> "user_password, " &_
> "user_email," &_
> "user_add, " &_
> "user_ccnumber, " &_
> "user_ccexpires," &_
> "user_ccname" &_
> ") VALUES ( " &_
> " '" & fixQuotes( newusername ) & "', " &_
> " '" & fixQuotes( newpassword ) & "', " &_
> " '" & fixQuotes( email ) & "', " &_
> " '" & fixQuotes( address ) & "', " &_
> " '" & fixQuotes( ccnumber ) & "', " &_
> " '" & ccexpires & "', " &_
> " '" & fixQuotes( ccname ) & "' " &_
> ")"
> Con.Execute sqlString
> ' Use the new username and password
> username = newusername
> password = newpassword
> ' Add Cookies
> addCookie "username", username
> addCookie "password", password
E> ND SUB
>
S> UB updateUser
> ' Get Registration Fields
> address = TRIM( Request( "address" ) )
> ccnumber = TRIM( Request( "ccnumber" ) )
> ccexpires = TRIM( Request( "ccexpires" ) )
> ccname = TRIM( Request( "ccname" ) )
> ' Check For Required Fields
> backpage = "checkout.asp"
> IF address = "" THEN
> errorForm "You must enter your address.", backpage
> END IF
> IF ccnumber = "" THEN
> errorForm "You must enter your credit card number.", backpage
> END IF
> IF ccexpires = "" THEN
> errorForm "You must enter your credit card expiration date.",
backpage
> END IF
> IF ccname = "" THEN
> errorForm "You must enter the name that appears on your credit
card.",
b> ackpage
> END IF
> ' Check for Necessary Field Values
> IF INSTR( ccnumber, "*" ) = 0 THEN
> IF NOT validCCNumber( ccnumber ) THEN
> errorForm "You did not enter a valid credit card number", backpage
> END IF
> END IF
> IF NOT isDATE( ccexpires ) THEN
> errorForm "You did not enter a valid credit card expiration date",
b> ackpage
> END IF
> ' Update user information in the database
> sqlString = "UPDATE users SET " &_
> "user_add='" & fixQuotes( address ) & "', " &_
> "user_ccnumber='" & ccnumber & "', " &_
> "user_ccexpires='" & ccexpires & "'," &_
> "user_ccname='" & fixQuotes( ccname ) & "' " &_
> "WHERE user_id=" & userID
> Con.Execute sqlString
E> ND SUB
>
> FUNCTION invalidEmail( email )
> IF INSTR( email, "@" ) = 0 OR INSTR( email, "." ) = 0 THEN
> invalidEmail = TRUE
> ELSE
> invalidEmail = FALSE
> END IF
E> ND FUNCTION
> FUNCTION validCCNumber( ccnumber )
> ccnumber = CleanCCNum( ccnumber )
> IF ccnumber = "" THEN
> validCCNumber = FALSE
> ELSE
> isEven = False
> digits = ""
> for i = Len( ccnumber ) To 1 Step -1
> if isEven Then
> digits = digits & CINT( MID( ccnumber, i, 1) ) * 2
> Else
> digits = digits & CINT( MID( ccnumber, i, 1) )
> End If
> isEven = (Not isEven)
> Next
> checkSum = 0
> For i = 1 To Len( digits) Step 1
> checkSum = checkSum + CINT( MID( digits, i, 1 ) )
> Next
> validCCNumber = ( ( checkSum Mod 10) = 0 )
> END IF
E> nd Function
> FUNCTION alreadyUser( theUsername )
> sqlString = "SELECT user_username FROM users " &_
> "WHERE user_username='" & fixQuotes( theUsername ) & "'"
> SET rst = Con.Execute( sqlString )
> IF rst.EOF THEN
> alreadyUser = FALSE
> ELSE
> alreadyUser = TRUE
> END IF
> rst.Close
E> ND FUNCTION
>
> FUNCTION CleanCCNum( ccnumber )
> FOR i = 1 TO LEN( ccnumber )
> IF isNumeric( MID( ccnumber, i, 1 ) ) THEN
> CleanCCNum = CleanCCNum & MID( ccnumber, i, 1 )
> END IF
> NEXT
E> ND FUNCTION
>
%> >
>
> register.asp:
> <%
n> ewusername = TRIM( Request( "newusername" ) )
n> ewpassword = TRIM( Request( "newpassword" ) )
e> mail = TRIM( Request( "email" ) )
a> ddress = TRIM( Request( "address" ) )
c> ctype = Request( "cctype" )
c> cnumber = TRIM( Request( "ccnumber" ) )
c> cexpires = TRIM( Request( "ccexpires" ) )
c> cname = TRIM( Request( "ccname" ) )
> submitpage = Request.ServerVariables( "SCRIPT_NAME" )
%> >
> <html>
<> head><title>Register</title></head>
<> body bgcolor="white">
> <center>
<> table width="500" border=0
> cellpadding=4 cellspacing=0>
<> tr>
> <td bgcolor="darkgreen">
> <font color="white" face="Arial">
> <b>Login</b>
> </font>
> </td>
<> /tr>
<> tr>
> <td>
> <form method="post" action="<%=submitpage%>">
> <input name="login" type="hidden" value="1">
> <input name="carid" type="hidden" value="<%=carID%>">
> <font face="Arial" size="2">
> Please enter your username and password:
> </font>
> <font face="Courier" size="2">
> <p><b>username:</b>
> <input name="username" size="20"></b>
> <br><b>password:</b>
> <input name="password" size="20"></b>
> <input type="submit" value="Login">
> </font>
> </form>
> </td>
<> /tr>
<> tr>
> <td bgcolor="darkgreen">
> <font color="white" face="Arial">
> <b>Register</b>
> </font>
> </td>
<> /tr>
<> tr>
> <td>
>
> <form method="post" action="<%=submitpage%>">
> <input name="register" type="hidden" value="1">
> <input name="carid" type="hidden" value="<%=carID%>">
> <font face="Arial" size="2">
> If you are a new user, please register by completing the following
form:
> </font>
> <font face="Arial" size="2" color="darkgreen">
> <p><b>Login Information:</b>
> </font>
> <font face="Courier" size="2">
> <br><b>username:</b>
> <input name="newusername" size=20 maxlength
> value="<%=Server.HTMLEncode( newusername )%>">
> <br><b>password:</b>
> <input name="newpassword" size=20 maxlength
> value="<%=server.HTMLEncode( newpassword )%>">
> <br><b>email address:</b>
> <input name="email" size=30 maxlength=75
> value="<%=Server.HTMLEncode( email )%>">
> </font>
> <font face="Arial" size="2" color="darkgreen">
> <p><b>Address Information:</b>
> </font>
> <font face="Courier" size="2">
> <br><b>address:</b>
> <input name="address" size=20 maxlength=50
> value="<%=Server.HTMLEncode( address )%>">
> <br>
> </font>
> <font face="Arial" size="2" color="darkgreen">
> <p><b>Payment Information:</b>
> </font>
> <br><b>credit card number:</b>
> <input name="ccnumber" size=20 maxlength
> value="<%=Server.HTMLEncode( ccnumber )%>">
> <br><b>credit card expires:</b>
> <input name="ccexpires" size=20 maxlength
> value="<%=Server.HTMLEncode( ccexpires )%>">
> <br><b>name on credit card:</b>
> <input name="ccname" size=20 maxlength
> value="<%=Server.HTMLEncode( ccname )%>">
> <input type="submit" value="Register">
> </font>
> </form>
> </td>
<> /tr>
<> /table>
> </body>
<> /html>
>
>
>
|
|
 |