现在看到很多的网络购物网站都有购物车,请问购物车用ASP是如何实现的?
---------------------------------------------------------------
一般来说用Session或cookie实现~
---------------------------------------------------------------
贴个CODE给你参考:
1
2if session("username")="" then
3response.redirect "index.asp"
4else
5
6sql="Select * From personal Where username='"&session("username")&"'"
7rs.Open sql,conn,1,1
8
9BookID=request("bookid")
10
11ProductList = Session("ProductList")
12Products = Split(BookID, ", ")
13For I=0 To UBound(Products)
14PutToShopBag Products(I), ProductList
15Next
16Session("ProductList") = ProductList
17
18ProductList = Session("ProductList")
19If Len(ProductList) = 0 Then
20Response.Redirect "index.asp"
21response.end
22end if
23
24
25Set conn1 = Server.CreateObject("ADODB.Connection")
26conn1.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("book.mdb")
27set rs1=server.createobject("adodb.recordset")
28sql1="Select * From book Where BookID in ("&ProductList&") order by BookID"
29rs1.Open sql1,conn1,1,1
30
31
32address=rs("address1")&"
<br/>
<br/>
<br/>
1<html>
2<head>
3<meta content="text/html; charset=utf-8" http-equiv="Content-Type"/>
4<link href="regstyle.css" rel="stylesheet" type="text/css"/>
5<title>```
6=session("username")
7```的订购单</title>
8</head>
9<body bgcolor="eeeeee">
10<center>
11<form action="user_order.asp" method="post" name="form">
12<table bgcolor="ffffff" border="0" cellpadding="4" cellspacing="1" width="600">
13<tr align="center">
14<td background="images/topcell.jpg" colspan="2" height="30" valign="bottom"><b><font color="#ffffff">```
15=rs("christianname")
16```的订单信息</font></b></td>
17</tr>
18<tr>
19<td bgcolor="#cceeff" colspan="2" height="23"><b>用户信息</b></td>
20</tr>
21<tr bgcolor="eeeeee">
22<td height="30" width="160"><b>英文名</b></td>
23<td height="30" width="440">```
24=rs("firstname")
25```</td>
26</tr>
27<tr bgcolor="eeeeee">
28<td height="30"><b>公司电话</b></td>
29<td height="30">```
30=rs("phone")
31```</td>
32</tr>
33<tr bgcolor="eeeeee">
34<td height="30"><b>手提电话</b></td>
35<td height="30">```
36=rs("mobile")
37```</td>
38</tr>
39<tr bgcolor="eeeeee">
40<td height="30"><b class="t">Email Address</b></td>
41<td height="30">```
42=rs("email")
43```</td>
44</tr>
45<tr bgcolor="eeeeee">
46<td height="30" valign="top"><b>公司地址</b></td>
47<td height="30">```
48=address
49```</td>
50</tr>
51</table>
52<table bgcolor="ffffff" border="0" cellpadding="4" cellspacing="1" width="600">
53<tr>
54<td bgcolor="#cceeff" colspan="5" height="23"><b>订单信息</b></td>
55</tr>
56<tr align="center" bgcolor="ffffcc" height="26">
57<td width="250"><b>书名</b></td>
58<td width="60"><b>编号</b></td>
59<td width="80"><b>单价</b></td>
60<td width="60"><b>数量</b></td>
61<td width="150"><b>总价</b></td>
62</tr>
dim Num(10)
For i=0 to rs1.recordcount-1
If rs1.EOF Then Exit For
Quatity = CInt( Request( "Q_" & rs1("BookID")) )
If Quatity <= 0 Then
Quatity = CInt( Session(rs1("BookID")) )
If Quatity <= 0 Then Quatity = 1
End If
Session(rs1("BookID")) = Quatity
Sum = Sum + csng(rs1("Price")) * Quatity
Sum=FormatNumber(Sum,2)
Num(i)=Quatity
1<tr bgcolor="eeeeee">
2<td align="left">```
3=rs1("BookName")
4```</td>
5<td align="left" class="t">```
6=rs1("TypeID")
7```</td>
8<td align="left" class="t">HK$```
9=FormatNumber(rs1("Price"),2)
10```</td>
11<td align="center" class="t"><input &="" ```"="" maxlength="4" name="```
12=" q_"="" rs1("bookid")="" size="4" type="text" value="```
13=Quatity
14```"/></td>
15<td align="left" class="t">HK$```
16=FormatNumber(csng(rs1("Price"))*Quatity,2)
17```</td>
18</tr>
19
rs1.MoveNext
Next
1<tr bgcolor="#cceeff">
2<td colspan="3" height="23"><b>本次订购总价格:</b> <font class="t">HK$```
3=Sum
4```</font></td>
5<td align="right" colspan="2" height="23"><input name="Submit" type="submit" value="更改数量"/></td>
6</tr>
7</table>
8<p>
9<a href="user_clear.asp">取消订购</a> <a href="index.asp">继续购物</a> <a "="" =sum="" ```"="" ```&sum="```" end="" href="user_orderok.asp?num=
for i=0 to 10
if Num(i)<>" if="" next="" num(i)&","="" response.write="" then="">确认订购
```end if
rs1.Close
Set rs1=Nothing
conn1.Close
Set conn1=Nothing
rs.Close
Set rs=Nothing
conn.Close
Set conn=Nothing
1\---------------------------------------------------------------
2
3*********************************
4Quatity = CInt( Request( "Q_" & rs1("BookID")) )
5If Quatity <= 0 Then
6Quatity = CInt( Session(rs1("BookID")) )
7If Quatity <= 0 Then Quatity = 1
8End If
9Session(rs1("BookID")) = Quatity
10Sum = Sum + csng(rs1("Price")) * Quatity
11Sum=FormatNumber(Sum,2)
12Num(i)=Quatity
13******************
14能说明一下这段是什么意思吗?
15还有Quatity = CInt( Request( "Q_" & rs1("BookID")) )中的
16( "Q_" & rs1("BookID")) 是什么意思?
17\---------------------------------------------------------------
18
19好代码!
20
21支持!!
22
23\---------------------------------------------------------------
24
If request.form("b1")="放入购物车" then
id=request.form("pid")
cpgg=request.form("cpgg")
num=cint(request.form("cpsl"))
sldw=request.form("sldw")
n=Year(Date())
y=Month(Date())
r=Day(Date())+1
If len(y)=1 then y="0"&y
If len(r)=1 then r="0"&r
sj=n&"/"&y&"/"&r
dim cid
cid=request.cookies("product"&id)("id")
If cid="" then
response.cookies("product"&id)("id")=id
response.cookies("product"&id)("gg")=cpgg
response.cookies("product"&id)("num")=num
response.cookies("product"&id)("dw")=sldw
response.cookies("product"&id).expires=sj
1<script language="javascript">
2alert('该产品已经保存在您的购物车里边!');
3window.close();
4</script>
end if
If cid=id then
response.cookies("product"&id)("id")=id
response.cookies("product"&id)("gg")=cpgg
response.cookies("product"&id)("num")=num+request.cookies("product"&id)("num")
response.cookies("product"&id)("dw")=sldw
response.cookies("product"&id).expires=sj
1<script language="javascript">
2alert('该产品已经保存在您的购物车里边!');
3window.close();
4</script>
end if
If request.cookies("product"&id)="" then
1<script language="javascript">
2alert('您的浏览器安全设置太高\n请将你的cookies打开!')
3</script>
end if
end if
1\---------------------------------------------------------------
2
31
4\---------------------------------------------------------------
5
6支持可惜没看明白</center></body></html>