Shopping Cart | tutorials | Shopping Cart database fields
Table: Pro_talbe:
ID Product number
Proname Product Name
Simages Product Small Picture
Table O_rder:
ID Order number
P_roid Product number
M_um Product Quantity
D_time Order Time
Table co_table:
ID Customer number
Nn_ame Customer Name
Tt_el Contact Tel
Ee_m_ail Customer Email
+++++++++++++++++++++++
Index. ASP source
+++++++++++++++++++++++
<% @LANGUAGE = "VBSCRIPT"%>
<!--#include file= "connections/conn.asp"-->
<%
Set Recordset1 = Server.CreateObject ("ADODB. Recordset ")
Recordset1.activeconnection = mm_conn_string
Recordset1.source = "SELECT * FROM Pro_table"
Recordset1.cursortype = 0
Recordset1.cursorlocation = 2
Recordset1.locktype = 3
Recordset1.open ()
Recordset1_numrows = 0
%>
<%
Dim repeat1__numrows
Repeat1__numrows =-1
Dim Repeat1__index
Repeat1__index = 0
Recordset1_numrows = recordset1_numrows + repeat1__numrows
%>
<title>untitled document</title>
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<body bgcolor= "#FFFFFF" text= "#000000" >
<table width= "583" border= "0" cellspacing= "0" cellpadding= "0" >
<%
while ((repeat1__numrows <> 0) and (not recordset1.eof))
%>
<tr>
<TD width= "140" ><%= (Recordset1.Fields.Item ("id"). Value)%></td>
<TD width= "171" ><%= (Recordset1.Fields.Item ("Proname"). Value)%></td>
<TD width= "272" ><%= (Recordset1.Fields.Item ("Simages"). Value)%></td>
<TD width= "272" ><a href= "cart.asp"? productid=<%= (Recordset1.Fields.Item ("id"). Value)%>&quantity=1 "> Buy </a></td>
</tr>
<%
Repeat1__index=repeat1__index+1
Repeat1__numrows=repeat1__numrows-1
Recordset1.movenext ()
Wend
%>
</table>
</body>
<%
Recordset1.close ()
%>
List products, here is a key point is: <a href= "cart.asp?" productid=<%= (Recordset1.Fields.Item ("id"). Value)%>&quantity=1 "> Buy </a>
Two parameters are passed here: Product ID "ProductID" Quantity: "Quantity"
+++++++++++++++++++++++++
The following is the source code of cart.asp:
+++++++++++++++++++++
<% @LANGUAGE = "VBScript"%>
<!--#include file= "connections/conn.asp"-->
<%
If not IsObject (session ("cart")) Then
Set session ("Cart") =createobject ("Scripting.Dictionary")
End If
Set cart=session ("cart")
PRODUCTID=CSTR (Request ("ProductID"))
Dim detail (1)
Detail (0) =int (Request ("Quantity"))
If Request ("ProductID") <> "then
If cart. Exists (ProductID) Then
Cart. Remove (ProductID)
End If
Cart.add Productid,detail
End If
Keys=cart.keys
Items=cart.items
Set session ("Cart") =cart
%>
<HTML>
<HEAD>
<TITLE> Zhejiang guang yuan Printing and Packaging Co., Ltd. </TITLE>
<meta http-equiv=content-type content= "text/html; charset=gb2312 ">
<link
href= "Index/index.css" Type=text/css rel=stylesheet>
<meta content= "MSHTML 5.50.4807.2300" name=generator>
</HEAD>
<body text= #000000 bgcolor= #ffffff leftmargin=0 topmargin=0 marginwidth= "0" marginheight= "0" >
<table width= "100%" border= "0" cellspacing= "0" cellpadding= "0" bgcolor= "#FFFFFF" >
<tr>
<TD width= "100%" valign= "Top" > <br>
<table border= "2" width= "100%" cellspacing= "0" cellpadding= "0" bordercolorlight= "#FFFFFF" bordercolordark= "# FFFFFF "bgcolor=" #D00000 "height=" 1 "align=" Center ">
<tr bgcolor= "#3399FF" >
<TD width= "25%" align= "center" height= "" ><font color= "#FFFFFF" > Product name </font></td>
&nbs