主题:  一步一步建校友录(5)

家伟

职务:普通成员
等级:1
金币:0.0
发贴:10
注册:2002/10/19 22:49:00
#12002/10/20 22:36:49
在上一期我们介绍了登陆login.asp的代码
这一期我们将介绍主体文件:liuyan.asp也就是登陆用户留言的代码,不是登陆的用户不能留言
好,我们只奔主题

<% '取session的值,判断用户是否登陆。如果没有转向nologin.htm
name=session("uname")
if name="" then
response.redirect"nologin.htm"
response.end
end if
'取 classid
if session("classid")="" then
classid=request("classid")
else
classid=session("classid")
end if
dim rs , sql
'打开words数据库
sql="select * from words order by date desc"
set rs = Server.CreateObject("ADODB.Recordset")
rs.open sql,conn,1,3
id=request("ID")
'取form表单传过来的content
content=request("content")
'为空的话转向index.asp
    if content=""then
    response.Redirect("index.asp")
    response.end
    end if
'对留言内容做去html标志的处理
    content=replace(content,"<","")
    content=replace(content,">","")
    content=replace(content,chr(13)& chr(10),"
")
'把留言的内容写到数据库
    rs.addnew
    rs("classid")=classid
    rs("content")=content
'写上留言人的名字
    rs("name")=session("uname")
    rs.update
    rs.close
set rs=nothing
conn.close
set conn=nothing
'留言完了转向班级主页
response.redirect("index2.asp?classid="&classid)
    
%>
这里需要说明的是index2.asp与index1.asp
没有多大的变化,只是你只有登陆以后才可以进入index2.asp
因为我们要用session记录你的信息,只有你登陆以后才可以享受更多的
功能,而index1.asp只是提供给游客看的!