% id = trim(request("id") & "") const ItemId = 0 const ItemPrice = 1 const ItemQuantity = 2 const ItemTitle = 3 if (id <> "" and isNumeric(id)) then 'look up item info dim price price = 0 set cn = server.CreateObject("adodb.connection") cn.connectionstring = constr cn.open set rs = cn.execute("Select ItemPrice, ItemTitle from Items where ItemId=" & id) if not rs.eof then price = rs("ItemPrice") title = rs("ItemTitle") end if cn.close: set cn = nothing if not isArray(Session("Cart")) then dim cart(4,100) else cart = Session("Cart") end if dim bFound bFound = false for i = 0 to ubound(cart,2) if cart(ItemId,i) = id then 'item found in cart, update it if (request.Form("quantity") = "0") then 'delete is empty, so update quantity cart(ItemId,i) = "" cart(ItemPrice,i) = "" cart(ItemQuantity,i) = "" cart(ItemTitle,i) = "" elseif (IsNumeric(request.Form("quantity"))) then cart(ItemQuantity,i) = request.Form("quantity") end if bFound = true exit for end if next if not bFound then 'add item to cart for i = 0 to ubound(cart,2) if (cart(ItemId,i) = "") then cart(ItemId,i) = id cart(ItemPrice,i) = price if request.Form("quantity") <> "" and isnumeric(request.Form("quantity")) then cart(ItemQuantity,i) = request.Form("quantity") else cart(ItemQuantity,i) = 1 end if cart(ItemTitle,i) = title exit for end if next end if dim tmpCart(4,100) j = 0 for i = 0 to ubound(cart,2) if (cart(ItemId,i) <> "") then tmpCart(ItemId,j) = cart(ItemId,i) tmpCart(ItemPrice,j) = cart(ItemPrice,i) tmpCart(ItemQuantity,j) = cart(ItemQuantity,i) tmpCart(ItemTitle,j) = cart(ItemTitle,i) j = j + 1 end if next Session("Cart") = tmpCart end if %>
![]() |
|
Images and materials used on this
site Copyright© Buddy and Dorothy Ebsen or used by permission.
All rights reserved. Site Maintenance by Advanced
Webpage Design