数据库连接代码
<%
dbname="chatroom.mdb"
set conn=server.createobject("adodb.connection")
connstr="dbq="+server.mappath(dbname)+";driver={microsoft access driver (*.mdb)};"
conn.open connstr
%>
html页面代码
postmsg
处理页面可保存在同一页面
<%
ac=request.querystring("act") '读取act 的值
if ac="addmsg" then 'act的值为addmsg
if request.form("hidden")<>"" then '私聊
session("chat")="" '清空session("chat")中的内容
'把要显示的私聊信息保存在application("chat")中
application("chat")=""&request.form("username")&"悄悄地对"&request.form("rname")&"说:"&request.form("msg")&""&time()&""
application("chatto")=request.form("rname") '聊天对象
application("owner")=request.form("username") '发言者
else '不是私聊
set rs=server.createobject("adodb.recordset") '创建recordset对象
sql="select * from chat" '查询数据库
rs.open sql,conn,1,3 '执行查询
rs.addnew '添加一条新记录
rs("fromname")=request.form("username") '发言者
rs("toname")=request.form("rname") '聊天对象
rs("chat")=request.form("msg") '显示的私聊信息
rs("posttime")=time() '提交时间
rs.update
rs.close
set rs=nothing
'增加一条聊天记录,将application("gchatnum")的值加1
application("gchatnum")=application("gchatnum")+1
end if
end if
%>源码下载地址