asp批量删除代码不起作用,请高手帮忙指正!

slmayi 2009-08-27 05:07:23
<!--#include file="conn.asp"-->
<%
if session("admin_name")="" then
response.redirect "error.asp?error=001"
end if
product_name=request("product_name")
sort_name=request("sort_name")
csort_name=request("csort_name")
%>
<%
'开始删除操作
action=request("action")
if action="delete" then
conn.execute("delete from page where [id] in ("& request.Form("idArray") &")")
response.Redirect("product_list.asp")
response.End()
end if

'if request("del")="true" then
'id=request("id")
'conn.execute "delete * from product where id=" & id
'url="product_list.asp?page=" & request("page") & "&sort_name=" & request("sort_name") & "&csort_name=" & request("csort_name")
'response.redirect url
'end if
%>
<html>
<head>
<title>电子购物程式后台管理</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link rel="stylesheet" href="css.css" type="text/css">
<style type="text/css">
<!--
.STYLE3 {color: #FFFFFF; font-weight: bold; }
-->
</style>
</head>
<body text="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<table width="100%" border="0" cellspacing="1" cellpadding="2" bgcolor="#FFFFFF" vspace="0" hspace="0">
<tr>
<td height="27" background="images/admin_bg_1.gif"> </td>
</tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="25" align="right"> </td>
</tr>
</table>

<table width="98%" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td align="right">
<%set rs=server.CreateObject("adodb.recordset")
rs.open "select * from sort order by sort_id",conn,1,1
if rs.eof and rs.bof then
response.write "目前还没有分类"
else%>
<select name="anclassid" onChange="var jmpURL=this.options[this.selectedIndex].value ; if(jmpURL!='') {window.location=jmpURL;} else {this.selectedIndex=0 ;}" >
<option selected>--请选择商品分类--</option>
<option value=product_list.asp>查看全部商品</option>

<%do while not rs.eof%>
<option value="product_list.asp?sort_name=<%=rs("sort_name")%>"><%=trim(rs("sort_name"))%></option>
<%rs.movenext
loop
end if
rs.close
set rs=nothing
%>

</select>
</td>
</tr>
</table>
<table width="97%" border="0" align="center" cellpadding="2" cellspacing="1" bgcolor="#000000">
<tr>
<td bgcolor="#6699CC" height="30" width="7%"><span class="STYLE3">ID</span></td>
<td width="23%" height="30" bgcolor="#6699CC"><span class="STYLE3">商品名</span></td>
<td width="12%" height="30" bgcolor="#6699CC"><span class="STYLE3">一级分类:</span></td>
<td width="11%" height="30" bgcolor="#6699CC"><span class="STYLE3">二级分类:</span></td>
<td width="8%" align="center" bgcolor="#6699CC"><span class="STYLE3">三级分类:</span></td>
<td width="8%" height="30" align="center" bgcolor="#6699CC"><span class="STYLE3">价格</span></td>
<td height="30" bgcolor="#6699CC"><span class="STYLE3">操作</span></td>
<td height="30" bgcolor="#6699CC" class="STYLE3">选择</td>
</tr>
<%
product_name=request("product_name")
sort_name=request("sort_name")
csort_name=request("csort_name")

sql="select * from product where product_name<>'' "
if product_name<>"" then sql=sql + " and product_name like '%"&product_name&"%'"
if sort_name<>"" then sql=sql + " and sort_name='"&sort_name&"'"
if csort_name<>"" then sql=sql + " and csort_name='"&csort_name&"'"
if request("type")="" then sql=sql + " order by id desc"
if request("type")="1" then sql=sql + " order by price desc"
if request("type")="2" then sql=sql + " order by buys desc"

Set rs=Server.CreateObject("ADODB.RecordSet")
rs.open sql,conn,1,2
if rs.eof then

Response.Write("<tr bgcolor=""#B0CBE6"">")
Response.Write("<td colspan=""11"" height=""50"" align=""center"" >目前本类还没有商品,请<a href=""productadd1.asp"">添加一个商品</a></td>")
Response.Write("</tr>")

else

if not isempty(request("page")) then
pagecount=cint(request("page"))
else
pagecount=1
end if

rs.pagesize=20
rs.AbsolutePage=pagecount
do while not rs.eof
%>
<form action="product_list.asp?action=delete" method="post">
<tr bgcolor="#B0CBE6">
<td width="7%" height="26" bgcolor="#FFFFFF" ><%=rs("id")%></td>
<td width="23%" height="26" bgcolor="#FFFFFF"><a href="../showproduct.asp?id=<%=rs("id")%>" target="_blank"><%=rs("product_name")%></a></td>
<td width="12%" height="26" bgcolor="#FFFFFF"><%=rs("sort_name")%></td>
<td width="11%" height="26" bgcolor="#FFFFFF"><%=rs("csort_name")%></td>
<td width="8%" align="center" bgcolor="#FFFFFF"><%=rs("cxsort_name")%></td>
<td width="8%" height="26" align="center" bgcolor="#FFFFFF"><%=rs("price")%></td>
<td width="12%" height="26" bgcolor="#FFFFFF"><a href="product_edit.asp?id=<%=rs("id")%>&product_name=<%=rs("product_name")%>&sort_name=<%=rs("sort_name")%>&csort_name=<%=rs("csort_name")%>">[查看|编辑]</a></td>
<td width="11%" height="26" bgcolor="#FFFFFF"> <a href="product_list.asp?del=true&id=<%=rs("id")%>&product_name=<%=rs("product_name")%>&sort_name=<%=sort_name%>&csort_name=<%=csort_name%>&page=<%=cstr(pagecount)%>">[删除]</a>
<input type="checkbox" name="selectRecord" onClick="selectBox(this)" value="<%=rs("id")%>" /> </td>
</tr>
<%
rs.movenext
i=i+1
if i>=rs.pagesize then exit do
loop
%>
<tr bgcolor="#D6DFF7">
<td height="35" colspan="8">
<div align="center"> 共 <b><%=rs.recordcount%></b> 个商品, 页次: <b><font color=red><%=pagecount%></font>/<%=rs.pagecount%></b>,
当前从第
<%
if pagecount<=1 then
response.write "<font color=red>1</font>"
else
response.write "<font color=red>" & pagecount*rs.pagesize-rs.pagesize+1 & "</font>"
end if
%>
个开始。
<% if pagecount=1 and rs.pagecount<>pagecount and rs.pagecount<>0 then%>
<a href="product_list.asp?product_name=<%=product_name%>&sort_name=<%=sort_name%>&csort_name=<%=csort_name%>&page=<%=cstr(pagecount+1)%>&type=<%=request("type")%>">下一页</a>
<% end if %>
<% if rs.pagecount>1 and rs.pagecount=pagecount then %>
<a href="product_list.asp?product_name=<%=product_name%>&sort_name=<%=sort_name%>&csort_name=<%=csort_name%>&page=<%=cstr(pagecount-1)%>&type=<%=request("type")%>">
上一页</a>
<%end if%>
<% if pagecount<>1 and rs.pagecount<>pagecount then%>
<a href="product_list.asp?product_name=<%=product_name%>&sort_name=<%=sort_name%>&csort_name=<%=csort_name%>&page=<%=cstr(pagecount-1)%>&type=<%=request("type")%>">
上一页</a> <a href="product_list.asp?product_name=<%=product_name%>&sort_name=<%=sort_name%>&csort_name=<%=csort_name%>&page=<%=cstr(pagecount+1)%>&type=<%=request("type")%>">
下一页</a>
<% end if%>
  直接到第
<select name="page">
<%for i=1 to rs.pagecount%>
<option value="<%=i%>"><%=i%></option>
<%next%>
</select>

<input type="submit" name="go" value="Go">
<input type="hidden" name="product_name" value=<%=product_name%>>
<input type="hidden" name="sort_name" value=<%=sort_name%>>
<input type="hidden" name="csort_name" value=<%=csort_name%>>
<input type="hidden" name="type" value=<%=request("type")%>>

<% call this_page_head() %>
<input type="hidden" name="idArray" />
<input type="button" value="全选" onClick="selectAll();" />
<input type="button" value="反选" onClick="selectOther();" />
<input type="submit" value="删除选中" onClick="return confirm('你确定删除吗?');" />
</div>
</td>
</tr>
</form>
<script>
function selectBox(box)
{
if(document.all.idArray.value!='')
{
document.all.idArray.value=document.all.idArray.value+","+box.value;
}
else
{
document.all.idArray.value=box.value;
}
}

function selectAll()
{
var allbox=document.all.selectRecord;
for(var i=0;i<allbox.length;i++)
{
allbox[i].checked=true;
}
}

function selectOther()
{
var allbox=document.all.selectRecord;
for(var i=0;i<allbox.length;i++)
{
if(allbox[i].checked==true)
{
allbox[i].checked=false;
}
else
{
allbox[i].checked=true;
}
}
}
</script>
</table>
<%
end if
rs.close
set rs=nothing
%>
</body>
</html>
...全文
69 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
shenymce 2009-08-27
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 toury 的回复:]
<%
  '开始删除操作
  action=request("action")
  if action="delete" then
    idArray=request("idArray")
    if len(idArray)=0 then
      response.write"参数传递错误,无法删除"
      response.end
    end if

    conn.execute("delete from page where [id] in ("& idArray &")")
    if err=0 then
      response.Redirect("product_list.asp")
      response.End()
    else
      response.write"出错啦!原因:"& err.description
  end if
[/Quote]
up
xb520hh 2009-08-27
  • 打赏
  • 举报
回复
up
[Quote=引用 2 楼 toury 的回复:]
<%
  '开始删除操作
  action=request("action")
  if action="delete" then
    idArray=request("idArray")
    if len(idArray)=0 then
      response.write"参数传递错误,无法删除"
      response.end
    end if

    conn.execute("delete from page where [id] in ("& idArray &")")
    if err=0 then
      response.Redirect("product_list.asp")
      response.End()
    else
      response.write"出错啦!原因:"& err.description
  end if
[/Quote]
toury 2009-08-27
  • 打赏
  • 举报
回复
<%
'开始删除操作
action=request("action")
if action="delete" then
idArray=request("idArray")
if len(idArray)=0 then
response.write"参数传递错误,无法删除"
response.end
end if

conn.execute("delete from page where [id] in ("& idArray &")")
if err=0 then
response.Redirect("product_list.asp")
response.End()
else
response.write"出错啦!原因:"& err.description
end if
slmayi 2009-08-27
  • 打赏
  • 举报
回复
帮帮忙!小弟不甚感激!

28,390

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧