Small Shopping Cart program based on cookies
Recently, a shopping cart program is required for project development.
Although there are many online users, I want to write them a long time ago. So I started it immediately.
There are a lot of code, and I feel that the method is not very good!
Post whatever you want. You can skip it ~!
Mycart. aspClient:
<Form method = "Post" Action = "mycart. asp">
<Table border = "0" width = "489" cellspacing = "1" id = "Table1">
<Tr>
<TD bgcolor = "# c0c0c0"> product name </TD>
<TD bgcolor = "# c0c0c0"> quantity </TD>
<TD bgcolor = "# c0c0c0"> price combination </TD>
<TD bgcolor = "# c0c0c0"> operation </TD>
</Tr>
<%
Nid = Split (request. Cookies ("mycartinfo") ("proid"), "|") 'item ID
Nnum = Split (request. Cookies ("mycartinfo") ("num"), "|") 'order quantity
Nprice = Split (request. Cookies ("mycartinfo") ("price"), "|") 'unit price
For k = 1 to ubound (NID) + 1
%>
<Tr>
<TD>
<%
Set rsw.conn.exe cute ("select productname from product where id =" & nid (k-1 )&"")
Response. Write RS (0)
Set rs = nothing
%>
</TD>
<TD> <input type = "text" name = "num" size = "4" value = "<% = nnum (k-1) %>"> </TD>
<TD> & yen; <% = nprice (k-1) * nnum (k-1) %> </TD>
<TD> <a href = "mycart. asp? Action = remove & location = K-1 %> "> remove </TD>
</Tr>
<% Next %>
<Tr>
<TD colspan = "4">
<P align = "center">
<Input type = "Submit" value = "clear shopping cart"Name = "action">
<Input type = "Submit" value = "continue shopping"Name = "action">
<Input type = "Submit" value = "Update quantity"Name = "action">
<Input type = "Submit" value = "checkout"Name = "action">
</TD>
</Tr>
</Table>
</Form>
Mycart. aspServer:
<%
Dim action
Action = request ("action ")
Select case action
'Add record
'From the "purchase" link on the product display page
Case "add"
Productid = htmlencode (request. querystring ("ID "))
Set rsw.conn.exe cute ("select * from product where id =" & productid &"")
If Rs. EOF then
Set rs = nothing
Response. Write ("corresponding product not found! ")
Response. End
End if
'Intercept
Theid = Split (request. Cookies ("mycartinfo") ("proid"), "| ")
Thenum = Split (request. Cookies ("mycartinfo") ("num"), "| ")
Theprice = Split (request. Cookies ("mycartinfo") ("price"), "| ")
'Clear
Response. Cookies ("mycartinfo") = ""
'Judge
Select case ubound (theid)
Case "-1"
Response. Cookies ("mycartinfo") ("proid") = productid 'product ID
Response. Cookies ("mycartinfo") ("num") = 1' Order Quantity
Response. Cookies ("mycartinfo") ("price") = RS ("price2") 'unit price
Response. Cookies ("mycartinfo"). expires = date + 7
Case "0"
If theid (0) = productid then
Response. Cookies ("mycartinfo") ("proid") = theid (0)
Response. Cookies ("mycartinfo") ("num") = thenum (0) + 1
Response. Cookies ("mycartinfo") ("price") = theprice (0)
Response. Cookies ("mycartinfo"). expires = date + 7
Else
Response. Cookies ("mycartinfo") ("proid") = theid (0) & "|" & productid 'product ID
Response. Cookies ("mycartinfo") ("num") = thenum (0) & "|" & "1" 'order quantity
Response. Cookies ("mycartinfo") ("price") = theprice (0) & "|" & RS ("price2") 'unit price
Response. Cookies ("mycartinfo"). expires = date + 7
End if
Case else
For Mm = 1 to ubound (theid) + 1
If theid (mm-1) = productid then 'This product ID already exists
If request. Cookies ("mycartinfo") ("proid") = "" then
Response. Cookies ("mycartinfo") ("proid") = theid (mm-1)
Response. Cookies ("mycartinfo") ("num") = thenum (mm-1) + 1
Response. Cookies ("mycartinfo") ("price") = theprice (mm-1)
Else
Response. Cookies ("mycartinfo") ("proid") = request. Cookies ("mycartinfo") ("proid") & "|" & theid (mm-1)
Response. Cookies ("mycartinfo") ("num") = request. Cookies ("mycartinfo") ("num") & "|" & thenum (mm-1) + 1
Response. Cookies ("mycartinfo") ("price") = request. Cookies ("mycartinfo") ("price") & "|" & theprice (mm-1)
End if
Response. Cookies ("mycartinfo") ("" & productid & "hasadd") = 1
Response. Cookies ("mycartinfo"). expires = date + 7
Else
If request. Cookies ("mycartinfo") ("proid") = "" then
Response. Cookies ("mycartinfo") ("proid") = theid (mm-1)
Response. Cookies ("mycartinfo") ("num") = thenum (mm-1)
Response. Cookies ("mycartinfo") ("price") = theprice (mm-1)
Response. Cookies ("mycartinfo"). expires = date + 7
Else
Response. Cookies ("mycartinfo") ("proid") = request. Cookies ("mycartinfo") ("proid") & "|" & theid (mm-1) 'product ID
Response. Cookies ("mycartinfo") ("num") = request. Cookies ("mycartinfo") ("num") & "|" & thenum (mm-1) 'order quantity
Response. Cookies ("mycartinfo") ("price") = request. Cookies ("mycartinfo") ("price") & "|" & theprice (mm-1) 'unit price
Response. Cookies ("mycartinfo"). expires = date + 7
End if
End if
Next
If request. Cookies ("mycartinfo") ("" & productid & "hasadd") <> "1" then
Response. Cookies ("mycartinfo") ("proid") = request. Cookies ("mycartinfo") ("proid") & "|" & productid "Product ID
Response. Cookies ("mycartinfo") ("num") = request. Cookies ("mycartinfo") ("num") & "|" & "1" 'order quantity
Response. Cookies ("mycartinfo") ("price") = request. Cookies ("mycartinfo") ("price") & "|" & RS ("price2") 'unit price
Response. Cookies ("mycartinfo"). expires = date + 7
End if
End select
Set rs = nothing
Response. Redirect ("mycart. asp ")
'Remove a commodity
Case "Remove"
Theid = Split (request. Cookies ("mycartinfo") ("proid"), "| ")
Thenum = Split (request. Cookies ("mycartinfo") ("num"), "| ")
Theprice = Split (request. Cookies ("mycartinfo") ("price"), "| ")
Response. Cookies ("mycartinfo") ("proid") = ""
Response. Cookies ("mycartinfo") ("num") = ""
Response. Cookies ("mycartinfo") ("price") = ""
For KK = 1 to ubound (theid) + 1
If theid (kk-1) = theid (request. querystring ("location") then
Else
If KK = 1 then
Response. Cookies ("mycartinfo") ("proid") = theid (kk-1)
Response. Cookies ("mycartinfo") ("num") = thenum (kk-1)
Response. Cookies ("mycartinfo") ("price") = theprice (kk-1)
Else
If request. Cookies ("mycartinfo") ("proid") = "" then
Response. Cookies ("mycartinfo") ("proid") = theid (kk-1)
Response. Cookies ("mycartinfo") ("num") = thenum (kk-1)
Response. Cookies ("mycartinfo") ("price") = theprice (kk-1)
Else
Response. Cookies ("mycartinfo") ("proid") = request. Cookies ("mycartinfo") ("proid") & "|" & theid (kk-1)
Response. Cookies ("mycartinfo") ("num") = request. Cookies ("mycartinfo") ("num") & "|" & thenum (kk-1)
Response. Cookies ("mycartinfo") ("price") = request. Cookies ("mycartinfo") ("price") & "|" & theprice (kk-1)
End if
End if
End if
Next
Response. Redirect ("mycart. asp ")
Case "Update quantity"
Response. Cookies ("mycartinfo") ("num") = ""
Newnum = htmlencode (request. Form ("num "))
Thenum = Split (newnum ,",")
If ubound (thenum) = 0 then
Response. Cookies ("mycartinfo") ("num") = thenum (0)
Else
For p = 1 to ubound (thenum) + 1
If p = 1 then
Response. Cookies ("mycartinfo") ("num") = thenum (p-1)
Else
Response. Cookies ("mycartinfo") ("num") = request. Cookies ("mycartinfo") ("num") & "|" & trim (thenum (p-1 ))
End if
Next
End if
Response. Redirect ("mycart. asp ")
Case "go to checkout"
'Go to the page asking the customer to enter the shipping information
'The order information can be called directly to cookies on the continuebuy. ASP page. The call method is similar to the method on this page.
Response. Redirect ("continuebuy. asp? Action = "& server. urlencode (" checkout "))
Response. End
Case "clear shopping cart"
Response. Cookies ("mycartinfo") = ""
Case "continue shopping"
Response. Redirect ("product. asp ")
End select
%>