简单购物车教程

2018-09-06 12:29

阅读:440

  数据库字段
表:pro_talbe:
id产品编号
proname产品名称
simages产品小图
表o_rder:
id订单编号
p_roid产品编号
m_um产品数量
d_time订购时间
表co_table:
id客户编号
nn_ame客户姓名
tt_el联系电话
ee_m_ail客户邮箱
+++++++++++++++++++++++
index.asp源码
+++++++++++++++++++++++

<%@LANGUAGE=VBSCRIPT%>
<!--#includefile=Connections/conn.asp-->
<%
setRecordset1=Server.CreateObject(ADODB.Recordset)
Recordset1.ActiveConnection=MM_conn_STRING
Recordset1.Source=SELECT*FROMpro_table
Recordset1.CursorType=0
Recordset1.CursorLocation=2
Recordset1.LockType=3
Recordset1.Open()
Recordset1_numRows=0
%>
<%
DimRepeat1__numRows
Repeat1__numRows=-1
DimRepeat1__index
Repeat1__index=0
Recordset1_numRows=Recordset1_numRows+Repeat1__numRows
%>
<html>
<head>
<title>UntitledDocument</title>
<metahttp-equiv=Content-Typecontent=text/html;charset=gb2312>
</head>
<bodybgcolor=#FFFFFFtext=#000000>
<tablewidth=583border=0cellspacing=0cellpadding=0>
<%
While((Repeat1__numRows<>0)AND(NOTRecordset1.EOF))
%>
<tr>
<tdwidth=140><%=(Recordset1.Fields.Item(id).Value)%></td>
<tdwidth=171><%=(Recordset1.Fields.Item(proname).Value)%></td>
<tdwidth=272><%=(Recordset1.Fields.Item(simages).Value)%></td>
<tdwidth=272><ahref=cart.asp?ProductID=<%=(Recordset1.Fields.Item(id).Value)%>quantity=1>购买</a></td>
</tr>
<%
Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
Recordset1.MoveNext()
Wend
%>
</table>
</body>
</html>
<%
Recordset1.Close()
%>
列出产品,这里有一个要点就是:<ahref=cart.asp?ProductID=<%=(Recordset1.Fields.Item(id).Value)%>quantity=1>购买</a>
这里传递了两个参数:产品ID“ProductID数量:“quantity

+++++++++++++++++++++++++
下面是cart.asp的源码:
+++++++++++++++++++++

<%@LANGUAGE=VBSCRIPT%>
<!--#includefile=Connections/conn.asp-->
<%
ifnotIsObject(session(cart))then
Setsession(cart)=CreateObject(Scripting.Dictionary)
endif
Setcart=session(cart)
productID=Cstr(request(productID))
dimdetail(1)
detail(0)=Int(request(quantity))
ifrequest(productID)<>then
ifcart.Exists(productID)then
cart.Remove(productID)
endif
cart.addproductID,detail
endif
keys=cart.keys
items=cart.items
setsession(cart)=cart
%>

<HTML>
<HEAD>
<TITLE>浙江广源印刷包装有限公司</TITLE>
<METAhttp-equiv=Content-Typecontent=text/html;charset=gb2312>
<LINK
href=index/index.csstype=text/cssrel=stylesheet>
<METAcontent=MSHTML5.50.4807.2300name=GENERATOR>
</HEAD>
<BODYtext=#000000bgColor=#ffffffleftMargin=0topMargin=0marginwidth=0marginheight=0>
<tablewidth=100%border=0cellspacing=0cellpadding=0bgcolor=#FFFFFF>
<tr>
<tdwidth=100%valign=top><br>
<tableborder=2width=100%cellspacing=0cellpadding=0bordercolorlight=#FFFFFFbordercolordark=#FFFFFFbgcolor=#D00000height=1align=center>
<trbgcolor=#3399FF>
<tdwidth=25%align=centerheight=19><fontcolor=#FFFFFF>商品名称</font></td>
<tdwidth=25%align=centerheight=19><fontcolor=#FFFFFF>购买数量</font></td>
<tdwidth=12%align=centerheight=19><fontcolor=#FFFFFF>更新</font></td>
<tdwidth=13%align=centerheight=19><fontcolor=#FFFFFF>删除</font></td>
</tr>
<%Dimlist__MMColParam
list__MMColParam=keys(i)%>
<%setlist=Server.CreateObject(ADODB.Recordset)
list.ActiveConnection=MM_conn_STRING
list.Source=SELECT*FROMpro_tableWHEREid=+Replace(list__MMColParam,’,’’)+
list.CursorType=0
list.CursorLocation=2
list.LockType=3
list.Open()
%>
<formmethod=postaction=cart.asponSubmit=returncheckform(this);>’更新产品数量用
<trbgcolor=#ECECFF>
<tdwidth=25%align=centerheight=1><ahref=detail.asp?productID=<%=keys(i)%>><fontcolor=#000077></font></a><%=(list.Fields.Item(proname).Value)%></td>
<tdwidth=25%align=centerheight=1>
<inputname=quantitysize=4class=editvalue=<%=items(i)(0)%>>
<inputtype=hiddenname=productIDvalue=<%=keys(i)%>>
</td>
<tdwidth=12%align=centerheight=1>
<inputtype=imageborder=0name=imageFieldsrc=images/ref.gifwidth=17height=19>
</td>
<tdwidth=13%align=centerheight=1><ahref=delcart.asp?productID=<%=keys(i)%>><imgsrc=images/del.gifwidth=17height=19border=0></a></td>
</tr>
</form>
<%
list.Close()
%>
<%next%>
<tr>
<tdwidth=75%bgcolor=#000000align=centerheight=1colspan=2>
<palign=right><fontcolor=#FFFFFF>总价合计:</font>
</td>
<tdwidth=25%bgcolor=#000000align=centerheight=1colspan=2><fontcolor=#FFFFFF>¥<%=price%></font></td>
</tr>
</table>
<palign=center><b><ahref=index.asp>继续选购</a><ahref=order.asp>付款</a></b>
</td>
</tr>
</table>
</BODY>
</HTML>

  

本新闻共2页,当前在第1页12

  


评论


亲,登录后才可以留言!