ASP如何更改购物车中商品数量和计算总价
我写的购物车程序是把数据存入数据库的.不是存进SESSION的.改变商品数量那里如果是一个就可以修改,但两个以上的话,程序就出错,请问哪位可以帮忙以下是程序代码:----...
我写的购物车程序是把数据存入数据库的.不是存进SESSION的.
改变商品数量那里如果是一个就可以修改,但两个以上的话,程序就出错,请问哪位可以帮忙
以下是程序代码:
--------zsorder.asp-----------
<%
Set conn = Server.CreateObject("ADODB.Connection")
conn.open mallDSN
set rs=server.createobject("ADODB.Recordset")
rs.open "select actionid,id,cpsl,yunfei,productnum,goods,style,state,paid from orders1 where username='"&username&"' and yunfei=0 ",conn,1,3
do while not rs.eof%>
<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="product.asp?id=<% = rs("id") %>" target="_blank">
<% = rs("productnum") %>
</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="修改" onClick="this.form.action='add.asp?action=cpsl&actionid=<%=rs("actionid")%>';this.form.submit()"></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>"
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','product.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></form>
-------add.asp------------
<%
dim id,action
username=session("userid")
Set conn = Server.CreateObject("ADODB.Connection")
conn.open mallDSN
action=request.QueryString("action")
select case action
case "cpsl"
set rs=server.createobject("ADODB.Recordset")
rs.open "select cpsl from orders1 where actionid="&request.QueryString("actionid"),conn,1,3
rs("cpsl")=CInt(request.form("cpsl"))
rs.update
rs.close
'response.Redirect "add.asp?action=show"
set rs=nothing
set rs=nothing
end if
end select
conn.close
set conn=nothing 展开
改变商品数量那里如果是一个就可以修改,但两个以上的话,程序就出错,请问哪位可以帮忙
以下是程序代码:
--------zsorder.asp-----------
<%
Set conn = Server.CreateObject("ADODB.Connection")
conn.open mallDSN
set rs=server.createobject("ADODB.Recordset")
rs.open "select actionid,id,cpsl,yunfei,productnum,goods,style,state,paid from orders1 where username='"&username&"' and yunfei=0 ",conn,1,3
do while not rs.eof%>
<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="product.asp?id=<% = rs("id") %>" target="_blank">
<% = rs("productnum") %>
</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="修改" onClick="this.form.action='add.asp?action=cpsl&actionid=<%=rs("actionid")%>';this.form.submit()"></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>"
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','product.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></form>
-------add.asp------------
<%
dim id,action
username=session("userid")
Set conn = Server.CreateObject("ADODB.Connection")
conn.open mallDSN
action=request.QueryString("action")
select case action
case "cpsl"
set rs=server.createobject("ADODB.Recordset")
rs.open "select cpsl from orders1 where actionid="&request.QueryString("actionid"),conn,1,3
rs("cpsl")=CInt(request.form("cpsl"))
rs.update
rs.close
'response.Redirect "add.asp?action=show"
set rs=nothing
set rs=nothing
end if
end select
conn.close
set conn=nothing 展开
2个回答
展开全部
这是因为当购物车有两种或以上的商品时,你的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,productnum,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="product.asp?id=<% = rs("id") %>" target="_blank">
<% = rs("productnum") %>
</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','product.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>
试试看,还有问题就给我在百度里留言!
我帮你修改了一下,就是把那个form表单位置改改就行了,改成每个商品都在自己的一个form表单里,这样就不会出错了!!
<%
Set conn = Server.CreateObject("ADODB.Connection")
conn.open mallDSN
set rs=server.createobject("ADODB.Recordset")
rs.open "select actionid,id,cpsl,yunfei,productnum,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="product.asp?id=<% = rs("id") %>" target="_blank">
<% = rs("productnum") %>
</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','product.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>
试试看,还有问题就给我在百度里留言!
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
一定会去看看的
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询