❶ asp實現購物車功能
這個怎麼說呢。你首先要把購物車的流程寫出來,無論什麼程序都是需要業務流專程才能做出來的。你把流屬程寫出來了,代碼就很簡單了。既然你已經用cookie寫出來了,那麼你就不能做一個臨時表來存儲這些數據,用戶登錄就記錄用戶,用戶沒登錄在他結帳的時候提醒登錄。。(PS:這只是一個思路,授人以魚,比如授人以漁。)代碼給你了,你也只是交差,你可以自己先思考一下。確實寫不了。。在Q我。
❷ asp的添加購物車代碼。。執行不了。。高手指點下。。
按照你的說法,它應該沒轉跳到go_login.asp頁面吧.
驗證登陸那也沒寫上response.end()
'***************************
<%if session("MM_username")="" then
response.write "<script>alert('很抱歉,您還沒有登錄,您需要先登陸後才能進入您的購物車!');window.location.href='go_login.asp';</script>"
response.end()
end if%>
'就執行到這,我登錄後進入該頁就沒有反應了,下面的代碼始終沒有執行
<%
if session("cart")="" or (not IsObject(session("cart"))) then
set Session("cart")=server.CreateObject("Scripting.Dictionary")
end if
Set cart=Session("cart")
proctID=Cstr(Request("Proct_ID"))
dim detail(1)
detail(0)=1
if Request("Proct_ID")<>"" then
if cart.Exists(proctID) then
Response.Write("<script>alert('對不起,您已經購買了該產品!');location='proct.asp';<script>")
Response.End
end if
cart.add proctID,detail
Response.Write("<script>alert('成功添加該產品!');location='proct.asp';<script>")
end if
%>
'*****************
如果還不行,就設置
on error resume next查錯語句,再配和在某個點設置response.write(變數a)
response.end()
'這樣可以在那個點可以追蹤到那個變數a的值,一步步查,看那裡有問題
❸ 想求一個完整的ASP購物車代碼
示用戶信息
首先登陸: 就是判斷資料庫里的記錄 是否存在用戶名欄位=帳號 and 密碼欄位=密碼 如果有這條記錄 那麼就是登陸成功 用session記住他的帳號 這就是登陸
購物車: 就是有個表 記錄商品的唯一值的欄位(一般是id欄位)和用戶的唯一欄位(一般是帳號) 這樣這個商就屬於這個人購物車內的商品了 一般有個商品個數欄位 記錄這個人買了多少件這個商品
顯示:(select * from [表] where 條件)這個是查詢sql 你應該會用吧 如果是查詢某人的購物車 就這樣寫(select * from [購物車表] where [用戶名欄位] = 用戶)上面已經說了 購物車表裡要有個用戶名欄位 來記錄是哪個用戶存放的物品
刪除:(delete from [購物車表] where [id]=記錄id and [用戶名欄位]=用戶)上面顯示里已經獲取到記錄的id和其他信息 在這里只需要id和用戶名 其實只需要id就可以要用戶名是為了更保險 有了用戶名欄位的限制 就只樣自己刪除自己的記錄
顯示用戶信息:如果你不會顯示用戶信息的話 那你還是去看看sql吧 (select * from [會員表] where [用戶名]=用戶名)獲取這個sql的記錄集
response.write(rs.("用戶名"))這樣就能在屏幕上列印出用戶名欄位的內容 其他欄位同上
❹ asp做的購物車,現在每點一款商品加到購物車後
同樣原理,比如商品的ID是29,價格是88,那麼把這個商品加到購物車,session("proctList")就記錄了這個29,session("Price")就記錄88;
❺ 購物車程序問題(asp+js+cookie)
以下是貼上來的,我以前也過的。我可以打包發給你。留言給我告訴我郵箱
cookie_buy.asp源代碼
<%session("username")="Inghot"%>
<p>
<input type="image" src="image/buy.gif" name="Submit" value="購買" title="購買" onClick="writeCookie('<%=session("username")%>','111','蘋果1','1',11)" />
<input type="image" src="image/buy.gif" name="Submit" value="購買" title="購買" onClick="writeCookie('<%=session("username")%>','222','蘋果2','1',12)" />
<input type="image" src="image/buy.gif" name="Submit" value="購買" title="購買" onClick="writeCookie('<%=session("username")%>','333','蘋果3','1',13)" />
<input type="image" src="image/buy.gif" name="Submit" value="購買" title="購買" onClick="writeCookie('<%=session("username")%>','444','蘋果4','1',14)" />
<input type="image" src="image/buy.gif" name="Submit" value="購買" title="購買" onClick="writeCookie('<%=session("username")%>','555','蘋果5','1',15)" />
<input type="image" src="image/buy.gif" name="Submit" value="購買" title="購買" onClick="writeCookie('<%=session("username")%>','666','蘋果6','1',16)" />
<input type="image" src="image/buy.gif" name="Submit" value="購買" title="購買" onClick="writeCookie('<%=session("username")%>','777','蘋果7','1',17)" />
<input type="image" src="image/buy.gif" name="Submit" value="購買" title="購買" onClick="writeCookie('<%=session("username")%>','888','蘋果8','1',18)" />
</p>
<p><a href="cookie_show.asp">去埋單</a></p>
<p style="text-align:center;">Copyright <a href="http://inghot.cn" target="_blank">Inghot.cn</a></p>
<script language="javascript">
//document.cookie="<%'=session("username")%>"+"=";//清空cookie
//writeCookie("cookie名稱","產品ID","產品名稱","產品數量",價格)
function writeCookie(name, ID, pro, num, pri)
{
var test=false;
var values="," + escape(ID) + "#" + escape(pro) + "#" + escape(num) + "#" + escape(pri);
var cookieValue = readCookie(name);
sss=cookieValue.split(",")
for (i=0;i<sss.length;i++){
s=sss[i].split("#");
for(j=0;j<s.length;j++){
if(s[0]==ID)
{
cookieValue=cookieValue.replace(","+sss[i],"");
nums=s[2];
test=true;
alert('你已經購買過些物品,將只在數量上添加!');
break;
}
}
}
if (test)
{
document.cookie = name + "=" + cookieValue+ "," + escape(ID) + "#" + escape(pro) + "#" + escape(parseInt(num)+parseInt(nums)) + "#" + escape(pri);
test=false;
}
else
{
document.cookie = name + "=" + cookieValue+values;
alert ('購買成功');
}
}
function readCookie(name)
{
var cookieValue = "";
var search = name + "=";
if(document.cookie.length > 0)
{
offset = document.cookie.indexOf(search);
if (offset != -1)
{
offset += search.length;
end = document.cookie.indexOf(";", offset);
if (end == -1) end = document.cookie.length;
cookieValue = document.cookie.substring(offset, end)
}
}
return cookieValue;
}
</script>
cookie_shop.asp源代碼
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>你的所購的物品</title>
<style type="text/css">
body {font-size:13px;}
.tb_b {border-bottom-width: 1px;border-bottom-style: dotted;border-bottom-color: #00A600;}
.tb_t {border-bottom-width: 1px;border-bottom-style: dotted;border-bottom-color: #00A600;}
.tb_tb {border-bottom-width: 1px;border-bottom-style: dotted;border-bottom-color: #00A600;border-top-width: 1px;border-top-style: dotted;border-top-color: #00A600;}
.tb_tbl {border-top-width: 1px;border-bottom-width: 1px;border-left-width: 1px;border-top-style: dotted;border-bottom-style: dotted;border-left-style: dotted;border-top-color: #00A600;border-bottom-color: #00A600;border-left-color: #00A600;}
.tb_bl {border-bottom-width: 1px;border-left-width: 1px;border-bottom-style: dotted;border-left-style: dotted;border-bottom-color: #00a600;border-left-color: #00a600;}
</style>
<script language="javascript">
<!--//
//name購物車名稱
function readCookie(name)
{
var cookieValue = "";
var search = name + "=";
if(document.cookie.length > 0)
{
offset = document.cookie.indexOf(search);
if (offset != -1)
{
offset += search.length;
end = document.cookie.indexOf(";", offset);
if (end == -1) end = document.cookie.length;
cookieValue = document.cookie.substring(offset, end)
}
}
return cookieValue;
}//readCookie(name) 此函數為返回已購買的所有內容,包括 物品ID,物品單價,物品名稱,物品數量
function stringToInteger (inputString)
{
return parseInt(inputString);
}//stringToInteger(inputString) 返回由字元串(inputString)轉換所得到的整數
function isNotaNumber (inputString)
{
return isNaN(inputString);
}//isNotaNumber(inputString) 返回一個 Boolean 值,指明inputString是否是保留值NaN(不是數字)
function UpdateCookie(name,Ids)
{
var buy_num=document.getElementById(Ids);
value=buy_num.value;
s=value.split("#");
value=escape(s[0])+"#"+escape(s[1])+"#"+escape(s[2])+"#"+escape(s[3])
var vvv="";
vvv=readCookie(name);//返回所有購買的內容
vvv=vvv.replace(','+value,"");//把要刪除的內容和其前面的","一起置空
document.cookie = name + "=" + vvv;//再把新的內容寫入cookie裡面
}//UpdateCookie(name, value) 刪除value這個內容
function ModifyCookie(name, valuex, ID, pro, num, pri)
{
var vvv="";
vvv=readCookie(name);//返回購買的所有內容,包括 物品ID,物品名稱,物品數量,物品單價
s=valuex.split("#");
valuex=escape(s[0])+"#"+escape(s[1])+"#"+escape(s[2])+"#"+escape(s[3])
vvv=vvv.replace(','+valuex,"");//把要修改的內容去掉
document.cookie = name + "=" + vvv + "," + escape(ID) + "#" + escape(pro) + "#" + escape(num) + "#" + escape(pri);//加上修改後得到的內容
//location.reload();
location.href='?';
}//ModifyCookie(name, valuex, ID, pro, num, pri) 修改內容,valuex為修改前的內容,value1-value4為修改後的內容
function clears()
{
document.cookie="<%=session("username")%>"+"=";
window.location.href='cookie_show.asp';
}//清除COOKIE
function AllPrice(num)
{
var All=document.getElementById("all");
All.innerHTML=num;
}//顯示價格
//-->
</script>
</head>
<body>
<table width="800" border="1" align="center" cellpadding="0" cellspacing="0" bordercolorlight="#00A600" bordercolordark="#FFFFFF">
<form name="buyForm" action="result.asp" method="post" target="_self">
<tr>
<td align="center"><img src="image/title_ico_01.gif" alt="購物車" width="165" height="68" /></td>
</tr>
<tr>
<td height="25"><img src="image/Buy_ico.gif" width="26" height="17" /> 所有商品總價 <span id="all" style="color:#FF0000;"></span>元 <span style="cursor:hand;" onClick="clears();">清空購物車</span>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="4%" height="25" align="center" class="tb_tb">序號</td>
<td width="44%" align="center" class="tb_tbl">物品名稱</td>
<td width="12%" align="center" class="tb_tbl">物品數量</td>
<td width="15%" align="center" class="tb_tbl">物品單價/元</td>
<td width="16%" align="center" class="tb_tbl">物品總價/元</td>
<td width="9%" align="center" class="tb_tbl">操作</td>
</tr>
<%
if session("username")<>"" then
buylist=request.Cookies(session("username"))'返回name為session("username")的cookie的內容
buylist_v=split(buylist,",")'用","把他們分開
for x=1 to ubound(buylist_v)'ubound 返回在buylist_v數組最大的維數,VBS數組下標為0(開始)
buylist_v_v=split(buylist_v(x),"#")'buylist_v_v為第一組數,即第x次購物的內容
buylist_v_x=buylist_v(x)'buylist_v_x為第x次購物的內容,與buylist_v(x)同
if buylist_v(x)<>"" then'判斷第x購物內容是否為空
if(ubound(buylist_v_v))<3 then
response.write("<script>alert('出現錯誤');document.cookie="""&session("username")&"""+"""=""";location.href='?';</script>")
response.End()
end if
ProID=buylist_v_v(0)'有四個內容讀四次,這個為 物品ID
ProName=buylist_v_v(1)'這個為 物品名稱
ProNum=buylist_v_v(2)'這個為 物品數量
ProPrice=buylist_v_v(3)'這個為 物品單價
AllPrice=AllPrice + (ProNum*ProPrice)
%>
<tr onMouseOver="this.style.backgroundColor='#F0FFEC'" onMouseOut="this.style.backgroundColor=''">
<td height="25" align="center" class="tb_b"><%=x%>
<input type="hidden" name="ID_<%=x%>" id="ID_<%=x%>" value="<%=ProID%>" /></td>
<td align="center" class="tb_bl"> <%=ProName%>
<input type="hidden" name="buy_<%=x%>" id="buy_<%=x%>" value="<%=buylist_v(x)%>" /></td>
<td align="center" class="tb_bl"><input name="num_<%=x%>" type="text" onChange="if(isNotaNumber(this.value)==true){alert('請輸入整數數字');this.value=1;}else{this.value=stringToInteger(this.value);};ModifyCookie('<%=session("username")%>','<%=buylist_v(x)%>','<%=ProID%>','<%=ProName%>',this.value,'<%=ProPrice%>');" value="<%=ProNum%>" size="10" maxlength="5" /></td>
<td align="center" class="tb_bl"> <%=ProPrice%>
<input type="hidden" name="pri_<%=x%>" id="pri_<%=x%>" value="<%=ProPrice%>" /></td>
<td align="center" class="tb_bl"> <%=ProPrice*ProNum%></td>
<td align="center" class="tb_bl"><img src="image/quit.gif" width="48" height="20" id="quit" name="quit" value="放棄" onClick="UpdateCookie('<%=session("username")%>','buy_<%=x%>');location.href='?';" /></td>
</tr>
<%
end if
next
response.write("<script>AllPrice('"&AllPrice&"');</script>")
end if
%>
</table>
</td>
</tr>
<tr>
<td height="25" align="center" style="display:block; vertical-align:middle;"><input type="image" value="提交" src="image/okay.gif" width="60" height="25" /> <img src="image/cancel.gif" width="60" height="25" border="0" title="取消" onClick="clears();" /></td>
</tr>
</form>
</table>
<p><a href="cookie_buy.asp">返回購物</a></p>
<p style="text-align:center;">Copyright <a href="http://inghot.cn" target="_blank">Inghot.cn</a></p>
</body>
</html>
result.asp源代碼
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>結果</title>
</head>
<body>
<p>
<%
nums=request.Form.count
price=0
id=""
num=""
'循環讀出提交過來的物品ID和數量,價格
'for i=1 to int(nums/3)
' id =id & request.Form("ID_"&i) & "|"
' num =num & request.Form("num_"&i) & "|"
' pri = pri & request.Form("pri_"&i) & "|"
'next
'response.write(id&"@"&num&"@"&pri&"<br />")
'當然一般價格是不會到這里得到的,所以取了個ID過來..這樣再根據ID去庫里取價格了
for i=1 to int(nums)
id = request.Form("ID_"&i)
num = request.Form("num_"&i)
pri = request.Form("pri_"&i)
price=price+(pri*num)
next
response.write("總共:"&price&"元")
%>
</p>
<p><a href="cookie_buy.asp">返回購物</a> <a href="cookie_show.asp">返回結算</a></p>
<p style="text-align:center;">Copyright <a href="http://inghot.cn" target="_blank">Inghot.cn</a></p>
</body>
</html>
❻ ASP怎麼實現購物車商品按店鋪分類
。。。商品表單、得有店鋪分類的欄位,按照欄位id分開提取就好了
❼ ASP如何更改購物車中商品數量和計算總價
這是因為當購物車有兩種或以上的商品時,你的actionid的值就會變成形如"12, 22, 25"的形式,成了字元串,而不是數值型,所以會出錯,
我幫你修改了一下,就是把那個form表單位置改改就行了,改成每個商品都在自己的一個form表單里,這樣就不會出錯了!!
<%
Set conn = Server.CreateObject("ADODB.Connection")
conn.open mallDSN
set rs=server.createobject("ADODB.Recordset")
rs.open "select actionid,id,cpsl,yunfei,proctnum,goods,style,state,paid from orders1 where username='"&username&"' and yunfei=0 ",conn,1,3
do while not rs.eof%>
<form name="form" method="post" action="add.asp?action=cpsl&actionid=<%=rs("actionid")%>">
<tr bgcolor="#FFFFFF">
<td width="7%" height="89" align="center" style='PADDING-LEFT: 5px'><input name="id" type="checkbox" checked="checked" value="<% = rs("id") %>" />
</td>
<td align="left" style='PADDING-LEFT: 5px' width="16%"><div align="center"><img src="<% = rs("goods")%>" width="75" height="75" border="0" /></div></td>
<td align="center" width="13%"><a class="a5" href="proct.asp?id=<% = rs("id") %>" target="_blank">
<% = rs("proctnum") %>
</a></td>
<td align="center" width="13%"><font color="#FF0000"> <%=rs("paid")%></font> 元</td>
<td align="center" width="13%"><font color="#FF0000">
<input name="cpsl" type="text" id="cpsl" style="font-size:12px" value="<% = rs("cpsl")%>" size=3 maxlength=20>
</font></td>
<td align="center" width="13%">
<input type="submit" name="Submit4" value="修改"></td>
<td align="center">
<%
response.Write "<a href=add.asp?action=del&actionid="&rs("actionid")&">"
response.Write "<img src=images/trash.gif border=0></a></td></tr></form>"
rs.movenext
loop
rs.close
set rs=nothing
response.write "<tr><td height=36 colspan=6 bgcolor=#FFFFFF ><div align=center> "
if action<>"addtocart" then
%>
<input name="Submit22" type="button" onclick="MM_goToURL('parent','proct.asp');return document.MM_returnValue" value="繼續購物" />
<input name="Submit23" type="button" value="去收銀台" onclick="this.form.action='zxoderok.asp';this.form.submit()" />
<%
end if
%>
</td>
</tr>
</table>
試試看,還有問題就給我在網路里留言!
❽ 幫忙翻譯asp購物車相關代碼!
Sub PutToShopBag( hw_ID,basket_count, proctList ,quantityList) '定義函數PutToShopBag()並傳入接受4個參數值分別安順序賦值給4個變數hw_ID,basket_count, proctList ,quantityList
If Len(proctList) = 0 Then 』如果proctList變數的長度為0 條件成立則執行如下語句
proctList = "" & hw_ID & "" 『proctList的值就等於hw_ID變數的值
quantityList="" & basket_count & "" 』quantityList變數的值就為basket_count變數的值
ElseIf InStr( proctList&",", hw_ID&"," ) <= 0 Then '否則 判斷proctList的值連接上字元","後是否包含hw_ID變數連接上字元","的值 <=0表示不包含 條件成立則執行如下語句
proctList = hw_ID & ""& ", " &proctList '為hw_ID變數連接上字元", "在連接上proctList變數的值後賦值給proctList變數
quantityList = basket_count & ", " &quantityList '同上
End If '結束條件選擇語句if
session("proctList")=proctList '定義名為proctList的session變數 值為proctList變數的值
session("quantityList")=quantityList '同上
End Sub
Sub PutToShopBagsecond( hw_ID,basket_count, proctList ,quantityList)
If Len(proctList) = 0 Then
proctList = "" & hw_ID & ""
quantityList="" & basket_count & ""
ElseIf InStr( proctList&",", hw_ID&"," ) <= 0 Then
proctList = hw_ID & ""& ", " &proctList
quantityList = basket_count & ", " &quantityList
End If
session("proctList")=proctList
session("quantityList")=quantityList
End Sub
proctList = session("proctList")
quantityList = session("quantityList")
if Request("hw_ID")<>"" then
PutToShopBag Request("hw_ID"), "1",proctList,quantityList
end if
session("proctList")=proctList
session("quantityList")=quantityList
Head="以下是您所選購的物品清單" '為Head變數賦值
If Request("clear") = "yes" Then '如果上一頁傳遞過來的參數clear的值yes
proctList = "" 'proctList 變數的值為空
quantityList = "" '同上
session("proctList") = proctList'同上
session("quantityList") = quantityList '同上
End If
If Request("MySelf") = "Yes" Then
proctList = ""
quantityList = ""
procts = Split(Request("hwID"), ", ") '把 上一頁傳遞過來的參數hwID的值以", "為分隔符 用split函數遍歷為數組賦值給procts
For I=0 To UBound(procts) ' for 循環 Ubound(procts)獲取procts數組的最大下標
j=UBound(procts)-i 'procts的最大下表減去i的值賦值給j變數 (下面應該是按照倒敘取值)
tempQuantity=Request("basket_count"&procts(j)) '獲取同名的basket_count參數的第j+1個的值並復制給tempQuantity
if tempQuantity="" then tempQuantity=1 '如果tempQuantity的值為空則重新為tempQuantity變數賦值為1
' j=i
PutToShopBagsecond procts(j), tempQuantity,proctList,quantityList '函數中調用函數puToShopBagsecond 並傳遞4個參數procts(j), tempQuantity,proctList,quantityList(這句我也不太清楚調用函數應該是call 函數名(參數))
Next
session("proctList") = proctList 『賦值語句
session("quantityList") = quantityList 『賦值語句
End If
❾ ASP購物車的問題!求教!
看起來你要往資料庫復裡面插數據制哦?
那 rsCheck.open strsql,conn,1,1 該改成 3,2啊
這個函數干嗎啊?看不懂哦…… 既然是SUB ,怎麼沒有 call puttoshopbag 啊?
<%
Sub PutToShopBag( Prodid, ProctList )
If Len(ProctList) = 0 Then
ProctList =Prodid
ElseIf InStr( ProctList, Prodid ) <= 0 Then
ProctList = ProctList&", "&Prodid &""
End If
End Sub
%>
你寫了那麼多request,總該把先前提交的那個表單貼貼啊……你好象連該頁的地址都沒有寫啊!
「參數類型不正確,或不在可以接受的范圍之內,或與其他參數沖突」……
我懷疑可能是="select ID,proct_name,Price,item_no from Proct where ID in ("&Session("ProctList")&")
這里的session錯了
❿ asp 購物車代碼問題
<td><input type="button" onclick="javascript:document.form1.action='update.asp?rowcount=<%=i%>&pid=<%=rs(1)%>&pcount=<%=rs(3)%>';document.form1.submit();"value="確認修改"></td>
改為
<td><input type="button" onclick="javascript:document.form1.action='update.asp?id=<%=rs("Id")%>&rowcount=<%=i%>';document.form1.submit();"value="確認修改"></td>
<%
'這里需要注意在上個頁面,有個i值,在這里就用到了,你要指明修改的是哪一行記錄
......
response.redirect("mycar.asp")'執行完之後重新跳轉到mycar.asp
%>
改為
<%
'只需商品id和修改後的數量值
dim id
id=request.querystring("id")
pcount=request.querystring("pcount")
sql="update buy set pcount ='"&pcount&"' where Id="&id
conn.execute sql
conn.close
set conn=nothing
response.redirect("mycar.asp")'執行完之後重新跳轉到mycar.asp
%>