sp; response.end
end if
end if
%>
‘Html页面显示部分,显示要修改的资料信息
……
3.2.14 保存修改的资料信息页
1. 页面中需要用户填写的Html表单元素
此页无需填写Html表单元素。
2. 页面所涉及的数据库表信息
此页使用了系统中的资料信息表main和教师信息表teacher。
3. 页面代码分析
‘引用创建数据库连接对象函数文件
<!--#include file="conn.asp"-->
‘引用判断是否是教师登陆文件
<!--#include file="isteacher.asp"-->
‘引用网站设置文件
<!--#include file="fenlei.asp"-->
<%’取得表单提交的信息
'on error resume next
course = server.htmlencode(trim(request("course")))
fileurl = server.htmlencode(trim(request("fileurl")))
content = server.htmlencode(trim(request("content")))
title = server.htmlencode(trim(request("title")))
typeid = trim(request("type"))
filesize = int(trim(request("filesize")))
id = request("id")
‘必须输入修改的资料的id号
if id = "" then
conn.close
set conn = nothing
response.write "<script>alert('请不要捣乱');top.window.location.href='teachermain.asp';</script>"
response.end
end if
‘必须输入资料名称
if course = "" then
conn.close
set conn = nothing
response.write "<script>alert('请输入资料名称');history.go(-1);</script>"
response.end
end if
if len(course) > 25 then
conn.close
set conn = nothing
response.write "<script>alert('资料名称不得超过25个汉字');history.go(-1);</script>"
response.end
end if
if fileurl = "" then
conn.close
set conn = nothing
response.write "<script>alert('请输入资料地址');history.go(-1);</script>"
response.end
end if
if len(fileurl) > 100 then
conn.close
set conn = nothing
response.write "<script>alert('资料地址不得超过100个英文字母');history.go(-1);</script>"
response.end
end if
if title = "" then
conn.close
set conn = nothing
response.write "<script>alert('请输入资料标题');history.go(-1);</script>"
response.end
end if
if len(title) > 25 then
conn.close
set conn = nothing
response.write "<script>alert('资料标题不得超过25个汉字');history.go(-1);</script>"
response.end
end if
if typeid = "" then
conn.close
set conn = nothing
response.write "<script>alert('请选择资料类型');history.go(-1);</script>"
response.end
end if
if filesize < 1 then filesize = 0
if content = "" then
conn.close
set conn = nothing
response.write "<script>alert('请输入简介');history.go(-1);</script>"
response.end
end if
‘取得要修改的资料信息
sql = "select * from main where mainid="&id
set rs = server.createobject("adodb.recordset")
rs.open sql,conn,1,3
‘如果要修改的资料信息不存在
if rs.bof and rs.eof then
rs.close
set rs = nothing
conn.close
set conn = nothing
response.write "<script>alert('请不要捣乱');top.window.location.href='teachermain.asp';</script>"
response.end
else
‘判断用户是否有修改资料的权限
if rs("idofteacher") <> int(session("teacherid")) and session("admin") <> "admin" then
rs.close
set rs = nothing
conn.close
set conn = nothing
response.write "<script>alert('这个资料不是你发布的,你想干什么?');top.window.location.href='teachermain.asp';</script>"
response.end
else
‘如果有修改权限就修改资料信息
rs("fileurl")=fileurl
rs("course")=course
rs("dateandtime")=now()
rs("content")=content
rs("title")=title
rs("idoftype")=cint(typeid)
rs("filesize")=filesize
‘修改成功
rs.update
‘关闭记录集对象
rs.close
set rs = nothing
‘关闭数据库连接对象
conn.close
set conn = nothing
end if
end if