add_bk.asp

来自「创建和运行动态、交互的Web服务器应用程序」· ASP 代码 · 共 106 行

ASP
106
字号
<!--#include file="conn.asp"-->
<%
if request.cookies("bookshop")("username")="" then
response.write "<script language=javascript>alert('对不起,您还没有登陆!');window.close()</script>"
response.End
end if

dim action,bk,index,i,count,purchase
 
    bk     = Session("mycart")  //调出保存信息的Session变量 
    bkindex= session("cartindex")
    action = request.QueryString("action")

    select case action
           case ""
    //检查购物车数量
    count=0
    for i=0 to bkIndex
	if bk(i,2)<>"" then
    	 if bk(i,2)>0 then
    	    count=count+1
    	 end if
        end if
     next 
 if count = 50 then
    response.write "<script language=javascript>alert('购物车已满!');window.location.reload('show_cart.asp')</script>"
 end if

//获得BOOKID号
if request.QueryString("bookid")="" then
   bookid=request("bookid")
else 
   bookid=request.QueryString("bookid")
end if

if bookid="" then
response.write "<script language=javascript>alert('对不起,您没有选择商品!');window.location.reload('javascript:window.close()')</script>"
response.End
end if

//获得purchase数
purchase	= request.QueryString("purchase")

              set rs=server.CreateObject("adodb.recordset")
                  rs.open "select * from shop_books where bookid="&bookid,conn,1,3
       bookname	= rs("bookname")
       shichangjia     = rs("shichangjia")
huiyuanjia      = rs("huiyuanjia")

   if purchase <>"" then
	purchase=Cint(purchase)

        '//检查数组
        for i=0 to bkindex
            '//是否重复
	    if bookid=bk(i,0) then

               bk(i,2)=bk(i,2)+purchase
                        Session("mycart") =  bk
                        bkindex           =  bkindex
                        session("cartindex")=bkindex

               response.redirect "show_cart.asp"
             end if
         next
               '//不重复
               if purchase>0 then
                        
                        bk(bkindex,0)=bookid
                        bk(bkindex,1)=bookname
                        bk(bkindex,2)=purchase
                        bk(bkindex,3)=shichangjia
                        bk(bkindex,4)=huiyuanjia

                        Session("mycart") =bk
                        bkindex           =  bkindex+1
                        session("cartindex")=bkindex
                end if
                response.redirect "show_cart.asp"

     else
	response.write "<script language=javascript>alert('你没有选择图书数量!');window.location.reload('javascript:window.close()')</script>"
        response.End
     end if

     '//修改数据
        case "ad_change"

        index   = request.form("index")
        purchase= request.form("purchase")
        bk(index,2)= purchase
        Session("mycart")= bk
        response.redirect"show_cart.asp"

       '//删除数据
        case "ad_delet"

        index	= request("index")
        for i=0 to 4
	    bk(index,i)="0"
        next
        Session("mycart")= bk
        response.redirect"show_cart.asp"

 end select%>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?