看看:上传图片名称总是无法写入数据库,什么地方错了?新手问题,立即给分!

Lengjian 2004-04-06 10:46:45
<%@ codepage ="936" %>
<%id=request("id")%>
<!--#include file="../../conn/dbconn2.asp" -->
<%
set rs=server.createobject("ADODB.recordset")
rs.Open "SELECT * FROM qyml Where cimg is null",conn,1,3
rs.addnew
nowtime=now()
sj=cstr(year(nowtime))+"-"+right("0"+cstr(month(nowtime)),2)+"-"+right("0"+cstr(day(nowtime)),2)
%>
<!--#include FILE="upload.inc"-->
<%dim upload,file,formName,formPath,iCount
set upload=new upload_F ''建立上传对象
'--------将日期转化成文件名--------
function MakedownName()
dim fname
fname = now()
fname = replace(fname,"-","")
fname = replace(fname," ","")
fname = replace(fname,":","")
fname = replace(fname,"PM","")
fname = replace(fname,"AM","")
fname = replace(fname,"上午","")
fname = replace(fname,"下午","")
fname = int(fname) + int((10-1+1)*Rnd + 1)
MakedownName=fname
end function
formPath="mvp/"
iCount=0
for each formName in upload.file ''列出所有上传了的文件
set file=upload.file(formName) ''生成一个文件对象
if file.FileSize>0 then ''如果 FileSize > 0 说明有文件数据
newname=MakedownName()&"."&mid(file.FileName,InStrRev(file.FileName, ".")+1)
file.SaveAs Server.mappath(formPath&newname) ''保存文件
iCount=iCount+1
else
response.write "未找到文件   <A HREF=javascript:history.back(1)>返回</A>"
response.end
end if
next
set rs=server.CreateObject("ADODB.RecordSet")
rs.open "select * from qyml where id="&id,conn,1,3
rs.addnew
rs("cimg")=formPath&newname
rs.update
rs.close
set rs=nothing
conn.close
set upload=nothing ''删除此对象
%>
<link rel="stylesheet" type="text/css" href="../style.css">
<body bgcolor="#FFFFFF" marginheight=0 marginwidth=0 leftmargin=0>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<BODY>
<div align="center">
<center>
<TABLE border=0 bordercolorlight='#FFFFFF' bordercolordark=#FFFFFF cellspacing=3 cellpadding=3 width="319" style="border-collapse: collapse" bordercolor="#111111" height="141">
<TR>
<TD width="315" bgcolor="#FBFDFF" height="132">
<p align="center">文件已经成功上传,是否继续添加……<BR>
<%
response.write file.FilePath&file.FileName&" ("&cint(file.FileSize/1024)&"K) 上传 成功!<br>"
%> </p>
<P><P align="center"><a href="cimg_add.asp">继续添加</a>  <A HREF="javascript:window.close()">关闭窗口</A></TD>
</TR>
</table>
</center>
</div>
<%
set file=nothing
set upload=nothing ''删除此对象
%>
...全文
8 点赞 收藏 8
写回复
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
dafei0320 2004-04-08
rs.Open "SELECT * FROM qyml Where ----",conn,1,3
rs.addnew

rs.open "select * from qyml where id="&id,conn,1,3
rs.addnew


rs.close
回复
yxfangela 2004-04-07
set rs=server.createobject("ADODB.recordset")
rs.Open "SELECT * FROM qyml Where cimg is null",conn,1,3
rs.addnew
nowtime=now()
sj=cstr(year(nowtime))+"-"+right("0"+cstr(month(nowtime)),2)+"-"+right("0"+cstr(day(nowtime)),2)
后面写上rs.update
rs.close
set rs=nothing
回复
pizixt 2004-04-07
<%id=request("id")%> 这个id是怎么生成的?

下面这两句在前面有什么作用?而且没有rs.close,不报错??
rs.Open "SELECT * FROM qyml Where cimg is null",conn,1,3
rs.addnew

rs.open "select * from qyml where id="&id,conn,1,3
rs.addnew -------?
回复
Jacklyluo 2004-04-07
用insert 语句
mySQL="insert into qyml (cimg) values('"& file.FileName &"')"
con.execute mySQL
回复
Lengjian 2004-04-07
文件传上去了,可是数据库字段里没有插入数据!
回复
tlane 2004-04-07
<%id=request("id")%> 这个id是如何传递过来的?用户id,还是相册文件夹id?
如果是新增的话

rs.open "select * from qyml where id="&id,conn,1,3
rs.addnew
改为
rs.Open "select* from qyml",conn,1,3
rs.addnew
去掉上面的那段
set rs=server.createobject("ADODB.recordset")
rs.Open "SELECT * FROM qyml Where cimg is null",conn,1,3
rs.addnew
要不然怎么可能通过呢,会报错的...
回复
whb147 2004-04-06
你是说数据库里没有?还是说没有上传上去呀?
回复
genray 2004-04-06
file.SaveToFile Server.mappath("../"&FileName) ''保存文件
回复
发动态
发帖子
ASP
创建于2007-09-28

2.8w+

社区成员

ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
申请成为版主
社区公告
暂无公告