完整asp购物车代码.docx

上传人:小飞机 文档编号:3433302 上传时间:2023-03-13 格式:DOCX 页数:14 大小:39.39KB
返回 下载 相关 举报
完整asp购物车代码.docx_第1页
第1页 / 共14页
完整asp购物车代码.docx_第2页
第2页 / 共14页
完整asp购物车代码.docx_第3页
第3页 / 共14页
完整asp购物车代码.docx_第4页
第4页 / 共14页
完整asp购物车代码.docx_第5页
第5页 / 共14页
亲,该文档总共14页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述

《完整asp购物车代码.docx》由会员分享,可在线阅读,更多相关《完整asp购物车代码.docx(14页珍藏版)》请在三一办公上搜索。

1、完整asp购物车代码网上购物已成为生活的潮流,在网上购物之后,想要随时查看自己已买的东西,想要随时删除或修改某件商品数量,要怎么做呢?下面我就来写代码及释义。先来做用户登陆页面:<html><head><title>购物车的实现</title></head><body><formmethod=postaction=check.asp><tablewidth=200border=1><tr><tdwidth=107>用户名:</td><tdwidth=77><inputtype=textname=

2、usernameid=username/></td></tr><tr><td>密码:</td><td><inputtype=passwordname=userpassid=userpass/></td></tr><tr><tdcolspan=2><inputtype=submitvalue=登录></td></tr></table></form></body></html>然后来写接收用户所填写的信息以检查是否存在该用户的页面,如果存在该用户,那么

3、就跳到购物的首页:<%uname=request.Form(username)upass=request.Form(userpass)sql=select*fromuserswhereuname=&uname&andupass=&upass&setrs=server.CreateObject(adodb.recordset)rs.opensql,conn,3,1ifnotrs.eofthen用户登陆成功之后,将用户名放入session里,并给用户分配一个订单,就像去超市购物推着一个购物车,此时这个购物车是属于你的,用用户名和系统时间作为购物车的名字,然后跳转到购物首页。session(na

4、me)=unamesession(orderid)=time&unameresponse.Redirect(index.asp)else%><script>alert(用户名或密码不正确!);history.back;</script><%endifrs.closesetrs=nothingconn.closesetconn=nothing%>那么,接下来就是购物的首页了<!-#includefile=inc/conn.asp-><html><head>下面用css样式表将表格里的字体统一设置为14号字<styletype=text/cs

5、s><!-tablefont-size:14px;-></style></head><body><%如果用户没登陆就直接打开购物首页,那么就跳转到登陆页面ifsession(name)=thenresponse.Redirect(login.asp)endif%>做一个搜索的文本框,方便用户搜索商品。其原理是这样的:用户填入要搜索的商品后,通过表单提交到本页面,从数据库中查找像用户填写的字符串的商品,再显示出来<formmethod=postaction=index.asp><inputtype=textsize=15name=searc

6、hid=search/><inputtype=submitvalue=搜索/></form><%searchname=request.Form(search)得到用户填写的字符串sql=select*fromproductswherepnamelike%&searchname&%写sql语句,查找出结果setrs=server.CreateObject(adodb.recordset)设置一个结果集对象rs.opensql,conn,3,1whilenotrs.eof循环输出商品的相关信息%>每个商品下面都有一个购买按钮,需要做一个表单<formmethod=p

7、ostaction=buy.asp><tablestyle=float:left><tr><tdwidth=103rowspan=3><ahref=product.asp?id=<%=rs(0)%>><imgsrc=images/<%=rs(2)%>width=100height=100border=0></a><inputtype=hiddenname=idvalue=<%=rs(0)%>><inputtype=hiddenname=pricevalue=<%=rs(3)%>/></td&

8、gt<tdwidth=107>名称:<%=rs(1)%></td></tr><tr><td>价格:<%=rs(3)%></td></tr><tr><tdalign=center><inputtype=submitname=buyvalue=购买/></td></tr></table></form><%rs.movenext指向下一个记录wendrs.closesetrs=nothingconn.closesetconn=nothing%></body>

9、</html>如果用户想要查看商品更详细的信息,那么就应该将商品图片做成一个超链接,连接到product.asp,在该页面显示详细信息。在该页面也有一个购买按钮,点击之后同样跳到buy.asp:<!-#includefile=inc/conn.asp-><body><%pid=request.QueryString(id)response.Write(pid)sql=select*fromproductswherepid=&pidsetrs=server.CreateObject(adodb.recordset)rs.opensql,conn,3,1ifnotrs.

10、eofthen%><tablewidth=387height=119><tr><tdwidth=120rowspan=4><imgsrc=images/<%=rs(2)%>width=100height=100></td><tdwidth=276>名称:<%=rs(1)%></td></tr><tr><td>价格:<%=rs(3)%></td></tr><tr><tdheight=30><%=rs(4)%></td></tr><

11、tr><tdalign=center><inputtype=buttononclick=javascript:location.href=buy.asp?id=<%=rs(0)%>&price=<%=rs(3)%>value=购买></td>点击购买之后触发一个onclick事件,跳转到buy.asp</tr></table><%endifrs.closesetrs=nothingconn.closesetconn=nothing%></body></html>用户点击了购买以后,将该商品的id传到buy.as

12、p,下面来写buy.asp的代码:<!-#includefile=inc/conn.asp->将连接数据库的字符串包含进来<%pid=request(id)得到商品的idprice=request(price)得到商品的价格sql=select*frommrcarwherepid=&pid&andorderid=&session(orderid)&写sql语句来查询setrs=server.CreateObject(adodb.recordset)rs.opensql,conn,3,1如果用户所要购买的商品已经买过,那么就直接在原来的基础上加1,否则的话,就插入记录ifnotrs.

13、eofthensql=updatemrcarsetpcount=pcount+1wherepid=&pid&andorderid=&session(orderid)&conn.executesqlresponse.Redirect(mycar.asp)elsesql=insertintomrcar(orderid,pid,price,pcount)values(&session(orderid)&,&pid&,&price&,1)conn.executesqlresponse.Redirect(mycar.asp)endifrs.closesetrs=nothingconn.closesetc

14、onn=nothing%>执行完了sql语句之后将跳转到购物车页面,显示出用户所购买的商品。并且有修改数量的按钮和删除的超链接<!-#includefile=inc/conn.asp-><%sql=selecta.*,b.pnamefrommrcara,productsbwhereorderid=&session(orderid)&anda.pid=b.pidsetrs=server.CreateObject(adodb.recordset)rs.opensql,conn,3,1%><formmethod=postaction=update.aspname=form1&

15、gt<tableborder=1><tr><td>orderid</td><td>商品名称</td><td>商品id</td><td>单价</td><td>数量</td><td>删除</td><td>修改</td></tr><%sum=0i=1这里的i值到后边有介绍whilenotrs.eof将所购买的商品循环输出%><tr><td><%=session(orderid)%></td><td><%=rs(pn

16、ame)%></td><td><%=rs(1)%></td><td><%=rs(2)%></td><td><inputtype=textsize=10value=<%=rs(3)%>name=pcount></td><td><ahref=delete.asp?id=<%=rs(1)%>>删除</a></td><td><inputtype=buttononclick=javascript:document.form1.action=update.asp?

17、rowcount=<%=i%>&pid=<%=rs(1)%>document.form1.submit;value=确认修改></td></tr><%i=i+1sum=sum+cint(rs(2)*rs(3)计算总价格rs.movenextwendrs.closesetrs=nothingconn.closesetconn=nothing%></table></form><ahref=index.asp>返回继续购物</a>总金额为:<%=sum%>点击修改数量的按钮之后,就跳到update.asp:<!

18、-#includefile=inc/conn.asp-><%这里需要注意在上个页面,有个i值,在这里就用到了,你要指明修改的是哪一行记录i=request.querystring(rowcount)pcount=request.form(pcount)(i)pid=request.querystring(pid)(i)sql=updatemrcarsetpcount=&pcount&wherepid=&pid&andorderid=&session(orderid)&conn.executesqlconn.closesetconn=nothingresponse.redirect(my

19、car.asp)执行完之后重新跳转到mycar.asp%>同样点击删除之后,就跳到delete.asp,在该页面得到商品的id<!-#includefile=inc/conn.asp-><%pid=request.QueryString(id)response.write(pid)sql=deletefrommrcarwherepid=&pid&andorderid=&session(orderid)&conn.executesqlconn.closesetconn=nothingresponse.Redirect(mycar.asp)执行完之后重新跳转到mycar.asp%>一个简单的购物车做好了,它用到了连接数据库、数据库的增、删、改、查。

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 生活休闲 > 在线阅读


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号