ASP 购物车

请教高手结合这段代码 给小弟解释下是怎么修改商品数量的 谢谢了
<%@LANGUAGE="VBScript"%>
<!--#include file="Connections/conn.asp" -->
<%
if not IsObject(session("cart")) then
Set session("cart")=CreateObject("Scripting.Dictionary")
end if
Set cart=session("cart")
productID=Cstr(request("productID"))
dim detail(1)
detail(0)=Int(request("quantity"))
if request("productID")<>"" then
if cart.Exists(productID) then
cart.Remove(productID)
end if
cart.add productID,detail
end if
keys=cart.keys
items=cart.items
set session("cart")=cart
%>

<td width="25%" align="center" height="19"><font color="#FFFFFF">商品名称</font></td>
<td width="25%" align="center" height="19"><font color="#FFFFFF">购买数量</font></td>
<td width="12%" align="center" height="19"><font color="#FFFFFF">更新</font></td>
<td width="13%" align="center" height="19"><font color="#FFFFFF">删除</font></td>
</tr>
<% For i = 0 To cart.Count -1 %>
<% Dim list__MMColParam
list__MMColParam = keys(i) %>
<% set list = Server.CreateObject("ADODB.Recordset")
list.ActiveConnection = MM_conn_STRING
list.Source = "SELECT * FROM pro_table WHERE id = " + Replace(list__MMColParam, "’", "’’") + ""
list.CursorType = 0
list.CursorLocation = 2
list.LockType = 3
list.Open()
%>
<form method="post" action="cart.asp" onSubmit="return checkform(this);"> ’更新产品数量用
<tr bgcolor="#ECECFF">
<td width="25%" align="center" height="1"><a href="detail.asp?productID=<%=keys(i)%>"><font color="#000077" ></font></a><%=(list.Fields.Item("proname").Value)%></td>
<td width="25%" align="center" height="1">
<input name="quantity" size=4 class="edit" value="<%=items(i)(0)%>">
<input type="hidden" name="productID" value="<%=keys(i)%>">
</td>
<td width="12%" align="center" height="1">
<input type="image" border="0" name="imageField" src="images/ref.gif" width="17" height="19">
</td>
<td width="13%" align="center" height="1"><a href="delcart.asp?productID=<%=keys(i)%>"><img src="images/del.gif" width="17" height="19" border="0"></a></td>
</tr>
</form>
<%
list.Close()
%>
<% next %>
<tr >
<td width="75%" bgcolor="#000000" align="center" height="1" colspan="2">
<p align="right"><font color="#FFFFFF">总价合计:</font>
</td>
<td width="25%" bgcolor="#000000" align="center" height="1" colspan="2"><font color="#FFFFFF">¥<%=price%></font></td>
</tr>
</table>
<p align="center"><b><a href="index.asp">继续选购</a> <a href="order.asp">付款</a></b>

<form method="post" action="cart.asp" onSubmit="return checkform(this);">
<input type="image" border="0" name="imageField" src="images/ref.gif" width="17" height="19">
</form>
<%
if not IsObject(session("cart")) then
Set session("cart")=CreateObject("Scripting.Dictionary")
end if
Set cart=session("cart")
productID=Cstr(request("productID"))
dim detail(1)
detail(0)=Int(request("quantity"))
if request("productID")<>"" then
if cart.Exists(productID) then
cart.Remove(productID)
end if
cart.add productID,detail
end if
keys=cart.keys
items=cart.items
set session("cart")=cart
%>
这些地方是在更新的,表单里的那个input src 的是提交按钮
下面段是在更新数据的
温馨提示:答案为网友推荐,仅供参考
第1个回答  2010-04-29
<%@LANGUAGE="VBScript"%>
<!--#include file="Connections/conn.asp" -->
<%
if not IsObject(session("cart")) then '这里进行了判断 如果不存在 这个session("cart")的话,那么就创建一个
Set session("cart")=CreateObject("Scripting.Dictionary")
end if
Set cart=session("cart") '设置一个对象 cart的值是session("cart")
productID=Cstr(request("productID")) //格式化为字符
dim detail(1) '定义一个数组 里面 可以容纳2个单位
detail(0)=Int(request("quantity")) '第一个单位给值 Int(request("quantity")) 并且做了数字格式化 int()函数的操作
if request("productID")<>"" then '如果接受的request("productID")不是空的话 执行下面的语句
if cart.Exists(productID) then '如果 cart对象(前面建立的) 存在 productID变量的话 那么就把该变量给移除 然后下面肯定是 添加新的了 呵呵
cart.Remove(productID)
end if
cart.add productID,detail '这里进行新的添加
end if
keys=cart.keys '获取键 返回一数组
items=cart.items '获取值 Items 方法 描述返回一个包含 Dictionary 对象中所有条目的数组。
set session("cart")=cart
%>
相似回答