Database Connection Code
<%
Dbname= "Chatroom.mdb"
Set Conn=server.createobject ("Adodb.connection")
Connstr= "dbq=" +server.mappath (dbname) + ";d river={microsoft Access Driver (*.mdb)};"
Conn.Open ConnStr
%>
HTML page code
<title>postmsg</title>
<body topmargin= "0" leftmargin= "0" >
<table width= "100%" height= "border=" "0" >
<tr>
<TD height= "colspan=" 2 ">
<form action= "postmsg.asp?act=addmsg&myself=<%=request.querystring (" Myself ")%>&toname=<%= Request.QueryString ("ToName")%> "method=" Post "Name=" Form1 ">
<input readonly type=text name=fromname value= "<%=request.querystring (" Myself ")%>" >
Right
<select name= "Rname" >
<%if request.querystring ("toname") = "" Then%>
<option> everyone </option>
<%else%>
<option><%=request.querystring ("ToName")%></option>
<%end if
' Show number online
Set Rsout=server.createobject ("Adodb.recordset")
Sqlout= "SELECT * from online where ID order by id desc" ' All records are checked from data bitterness, sorted by ID
Rsout.open sqlout,conn,1,1 ' Execute query to save results in Rsout
For I=1 to 50 ' displays up to 50 user names in the dropdown box
%>
<option><%response.write (Rsout ("username"))%></option>
<%
Rsout.movenext ' points to the next record
If rsout.eof then exit for ' gets to the last record then jumps out for loop
Next
%>
</select>
Said:
<input name= "MSG" type= "text" size= ">"
<input name= "Submit" type= "submitted" value= "Submission" height= ">
<input name= "hidden" type= "submit" value= "Private Chat" >
<input name= "username" type= "hidden" id= "username" value= "<%response.write (Request.QueryString (" myself "))% > ">
</form>
</td>
</tr>
<tr>
<TD width= "602" height= "></td>"
<TD width= "185" ></td>
</tr>
</table>
</body>
Processing pages can be saved on the same page
<%
ac=request.querystring ("act") ' reads the value of the Act
The value of the If ac= "addmsg" then act is addmsg
If Request.Form ("hidden") <> "then" private chat
Session ("chat") = "" Empty the contents of the session ("chat")
' Keep the private chat information to be displayed in application (' chat ')
Application ("chat") = "<font size = 2>" &request.form ("username") & "Quietly to" &request.form ("Rname") & "said: <font color= black>" &request.form ("MSG") & "</font>" &time () & "</font>"
Application ("Chatto") =request.form ("rname") ' Chat object
Application ("owner") =request.form ("username") ' speaker
Else ' is not a private conversation
Set Rs=server.createobject ("Adodb.recordset") ' Creates a Recordset object
Sql= "SELECT * from chat" Query database
Rs.Open sql,conn,1,3 ' Execute query
Rs.addnew ' Add a new record
RS ("FromName") =request.form ("username") ' speaker
RS ("ToName") =request.form ("rname") ' Chat object
Private chat information displayed by RS ("chat") =request.form ("MSG")
RS ("Posttime") =time () ' Submit time
Rs.update
Rs.close
Set rs=nothing
' Add a chat record and add the value of application (' Gchatnum ') to 1
Application ("Gchatnum") =application ("Gchatnum") +1
End If
End If
%>
SOURCE Download Address
Http://down.111cn.net/down/code/asp/2010/1024/21402.html