标题:[求助]"删除所选(复选框)"时怎样才能同时删除数据库记录及相关文件 ...
只看楼主
thbwn
Rank: 1
等 级:新手上路
帖 子:235
专家分:0
注 册:2007-10-2
结帖率:80%
 问题点数:0 回复次数:2 
[求助]"删除所选(复选框)"时怎样才能同时删除数据库记录及相关文件

这段代码不知道哪有问题,删除所选时数据库记录删除正确,但所有文件都被删除了,不是相关文件被删除,请教各位大侠:

<!--#include file="conn.asp"-->
<%
id= trim(request("id"))
filename=trim(request("filename"))

if id <> "" or filename <> "" then
fileid = split(id,", ")
for i=0 to ubound(fileid)
if fileid(i) <> "" then
sql="delete from [file] where id="&fileid(i)
conn.execute(sql)
end if
next

filedel = split(filename,", ")
for i=0 to ubound(filedel)
set fso=server.createobject("Scripting.filesystemobject")
if fso.fileexists(server.mappath(""&SavePath&"/"&filedel(i)))=true then
fso.deletefile(server.mappath(""&SavePath&"/"&filedel(i)))
End if
next

end if

response.Redirect("show.asp")
%>

搜索更多相关主题的帖子: 复选 数据库 文件 fileid 
2007-10-02 11:11
thbwn
Rank: 1
等 级:新手上路
帖 子:235
专家分:0
注 册:2007-10-2
得分:0 

我把关联的前一页"show"发出来,大伙儿看看,这一页有没有问题:
<%@ codepage=936 %>
<!--#include file="conn.asp"-->
<%
dim i,intPage,page,pre,last,filepath
set rs = server.CreateObject("adodb.recordset")
sql="select * from file order by ID"
rs.PageSize = 15 //(HacKpp:这里设定每页显示的记录数
rs.CursorLocation = 3
rs.Open sql,conn,0,2,1 //(HacKpp:'这里执行你查询SQL并获得结果记录集
pre = true
last = true
page = trim(Request.QueryString("page"))

if len(page) = 0 then
intpage = 1
pre = false
else
if cint(page) =< 1 then
intpage = 1
pre = false
else
if cint(page) >= rs.PageCount then
intpage = rs.PageCount
last = false
else
intpage = cint(page)
end if
end if
end if
if not rs.eof then
rs.AbsolutePage = intpage
end if
%>

<html>
<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>木目ASP文件上传工具(川江号子修改版)</title>
<link rel="stylesheet" href="Data\style.css">
</head>
<SCRIPT language=JavaScript type=text/javascript>
function CheckAll(form) {
for (var i=0;i<form.elements.length;i++) {
var e = form.elements[i];
if (e.name == 'ID'){
e.checked = form.chkall.checked;
}
}
}
</SCRIPT>
<body style="text-align: center">

<div align="center">
<table width="150" border="1" align="center" cellpadding="3" cellspacing="1" bordercolor="#7B96BD" bordercolordark="#FFFFFF">
<tr>
<td height="22" align="center" bgcolor="#7C96B8"><font color="#FFFFFF">上传文件列表</font></td>
</tr>
</table>
<br>
<FORM name=kk action=del.asp method=post>
<table width="650" height="42" border="1" align="center" cellpadding="3" cellspacing="1" bordercolor="#7C96B8" bordercolordark="#FFFFFF">
<TR align="center">
<td width="10%" height="20" bgcolor="#006666" align="center"><font color="#FFFFFF">选择</font></td>
<td width="10%" height="20" bgcolor="#006666" align="center"><font color="#FFFFFF">ID</font></td>
<td width="25%" height="20" bgcolor="#006666" align="center"><font color="#FFFFFF">文件名</font></td>
<td width="20%" height="20" bgcolor="#006666" align="center"><font color="#FFFFFF">文件大小</font></td>
<td width="25%" height="20" bgcolor="#006666" align="center"><font color="#FFFFFF">上传时间</font></td>
<td width="10%"><p align="center">删除</p></td>
</tr>
<%if rs.EOF or rs.BOF then
response.write "<TR><td colspan=10 height=20><div align=center>暂时还没有任何上传文件</div></td></TR>"
end if
%>
<%
for i=1 to rs.PageSize
if rs.EOF or rs.BOF then exit for
%>
<tr align=center>
<input type=hidden name=filename value=<%=rs("filename")%> />
<td width="10%" height="20" align="center"><input type=checkbox name=ID id=id value=<%=rs("id")%> /></td>
<td width="10%" height="20" align="center"><%=rs("ID")%></td>
<td width="25%" align="center"><%=rs("fileName")%></td>
<td width="20%" align="center"><%=Split(Rs("contentlen"),".")(0)%>&nbsp;KB</td>
<td width="25%" align="center"><%=rs("uptime")%></td>
<td width="10%"><p align="center"><a href="filedel.asp?id=<%=rs("id")%>&SaveFileName=<%=rs("filename")%>">删除</a></p></td>
</tr>
<%
rs.movenext
next
%>
</table>
<p><DIV class=bottom><INPUT onclick=CheckAll(this.form) type=checkbox value=on
name=chkall> 全选&nbsp;&nbsp;<INPUT class=button onClick="if(confirm('删除后将不能恢复!您确定要删除吗?'))form.submit()" type=button value=删除所选></DIV> </p></FORM>
<center>

<table width="650" border="0" cellpadding="3" cellspacing="1" borderColorLight=#808080 borderColorDark=#ffffff>
<tr>
<%if rs.pagecount > 0 then%>
<td width="13%" align="left">当前页<%=intpage%>/<%=rs.PageCount%></td>
<%else%>
<td width="40%" align="left">当前页0/0</td><%end if%>
<td width="47%" align="right"> <a href="Show.asp?page=1">首页</a>|
<%if pre then%>
<a href="Show.asp?page=<%=intpage -1%>">上页</a>| <%end if%>
<%if last then%>
<a href="Show.asp?page=<%=intpage +1%>">下页</a> |<%end if%>
<a href="Show.asp?page=<%=rs.PageCount%>">尾页</a>|转到第
<select name="sel_page" onChange="javascript:location=this.options[this.selectedIndex].value;">
<%
for i = 1 to rs.PageCount
if i = intpage then%>
<option value="Show.asp?page=<%=i%>" selected><%=i%></option>
<%else%>
<option value="Show.asp?page=<%=i%>"><%=i%></option>
<%
end if
next
%>
</select>页</font>
</td>
</tr>
</table>
<p>&nbsp;</p>
<p><a href="upload.asp" target="_self"><font color="#0000FF">[返回上传页]</font></a>  <a href="mdbzip.asp" target="_self"><font color="#0000FF">[压缩数据库]</font></a></p>
</center>
</div>
</body>

</html>

[此贴子已经被作者于2007-10-2 11:15:00编辑过]


          人人为我,我为人人!
2007-10-02 11:12
thbwn
Rank: 1
等 级:新手上路
帖 子:235
专家分:0
注 册:2007-10-2
得分:0 
怎么没有回呢

          人人为我,我为人人!
2007-10-03 11:40



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-174601-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.102843 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved