Next, we begin to analyze the user login and Speech instance program: chatadd1.asp
1, User Login
<%Response.Buffer=true%> Specify Cache as True
<body bgcolor= "#F8E17A" >
<%if Request ("name") = "" then%> determine if the user name is empty to determine whether the user is in the chat interface
<%addr=request ("REMOTE_ADDR")%> get User IP
<form method= "POST" action= "chatadd1.asp" >
<p><input type= "hidden" name= "IP" value= "<%=addr%>" ><p> User Login Form
<p> Please enter anonymous: <input type= "text" name= "name" size= "" >
Password: <input type= "password" name= "pass" size= ">"
<%b1=request ("B1")
If b1= "Send" Then start to Judge user name and password
If Request ("name") = "" or request ("pass") = "" Then to determine whether the username and password are null
A= "name or password cannot be empty!<br>" if empty, define this error variable
Response.Redirect "Chatadd1.asp?a=" & A & "" error immediately returns to the login interface
End If
Set conn=server.createobject ("ADODB. Connection ") If the customer enters a non-empty, start querying the database
Connstr= "dbq=" +server.mappath ("Chat.mdb") + ";D river={microsoft Access DRIVER (*.mdb)};"
Conn.Open ConnStr
Sql= "SELECT * from user table WHERE name = '" & Request ("name") & "'" To see if this user exists in the database
Set Rs=conn. Execute (SQL)
If Rs.bof or rs.eof Then if the user is not yet in the database,
SZ = "'" & Request ("IP") &_ writes the user to the user database
"', '" & Request ("name") &_
"', '" & Request ("D4") &_
"', '" & Request ("Pass") & ""
into_db = "INSERT into user table (IP, name, gender, password) VALUES (" &_ Write to user database
SZ & ")"
Conn. Execute (into_db)
Else If the user already exists in the database, the
If Request ("Pass") <>rs ("password") Then see if his password is correct.
A= "The name has been used by someone else, or you have entered a password that is not!<br>" if the password is wrong, define the error message
Response.Redirect "Chatadd1.asp?a=" & A & "" immediately return to the login interface and return this error message
End If
End If
Time1=now If there are no errors in the login form, start to become an online user and enter the chat
Set conn=server.createobject ("ADODB. Connection ")
Connstr= "dbq=" +server.mappath ("Chat.mdb") + ";D river={microsoft Access DRIVER (*.mdb)};"
Conn.Open ConnStr
Sql= "SELECT * from online user table WHERE name = '" & Request ("name") & "'" To see if this user exists in the online list
Set Rs=conn. Execute (SQL)
If Rs.bof OR rs.eof Then If this user does not exist on the online list,
SZ = "'" & Request ("name") &_ Add this user to the online user table
"', '" & Request ("D4") &_
"', '" & Time1 & ""
into_db = "INSERT into online user table (name, sex, login time) VALUES (" &_ Add this user
SZ & ")"
Conn. Execute (into_db)
Name=request ("name")
Sex=request ("D4")
ming= "Administrator announced" the administrator began to announce the welcome of this (SIR/madam)
sz= "<font size=5 color= #FF0000 ><strong>" & "warmly welcome" & name & Sex & ""
INTO_DB2 = "INSERT into chat table (name, Speak) VALUES (' & Ming &" ', ' "& Sz &") "
Conn. Execute (INTO_DB2)
<p> color: <select name= "D1" size= "1" style= "Color:rgb (0,0,128)" >
<option value= "" > Black </option> color selection
<option value= "#ff0000" > Red </option>
<option value= "#008000" > Green </option>
<option value= "#0000FF" > Blue </option>
<option value= "#800080" > Purple </option>
<option value= "#008080" > Cyan </option>
<option value= "#800000" > Deep red </option>
<option value= "#00ff00" > Green Grass </option>
<option value= "#00ffff" > Sea blue </option>
</select>
<%
Set conn=server.createobject ("ADODB. Connection ") Query update online users
Connstr= "dbq=" +server.mappath ("Chat.mdb") + ";D river={microsoft Access DRIVER (*.mdb)};"
Conn.Open ConnStr
Sql= "SELECT * from online user table"
Set Rs=conn. Execute (SQL)
%>
Objects: <select name= "D2" size= "1" style= "Color:rgb (0,0,128)" > select speakers from online users
<option value= "Everyone" > Everyone </option>
<%do While not rs.eof online user form
If Rs ("name") =request ("D2") Then
S= "selected" Here the condition defines s is to maintain the invariance of the Speaking object,
else so that users do not have to choose the speaker every time, you can also
S= "" With the expression of the same.
End If%>
<option <%=s%> value= "<%=rs (" name ")%>" ><%=rs ("name")%> (<%=rs ("Sex")%>) </option>
<%
Rs.movenext
Loop
%>
</select>
<%
B3=request ("B3")
If b3= "Speak" Then ready to write the user's address to the chat table
Set conn=server.createobject ("ADODB. Connection ")
Connstr= "dbq=" +server.mappath ("Chat.mdb") + ";D river={microsoft Access DRIVER (*.mdb)};"
Conn.Open ConnStr
%>
<%
Word=request ("word")
If Request ("word") = "" Then if you have not written anything on the floor, the default speech for two eyes open, is in a daze
Word= "Two eyes open, is in a daze ..."
End If
%>
<%
SZ = "'" & Request ("IP") &_ writes the user to the chat table
"', '" & Request ("name") &_
"', '" & Request ("D1") &_
"', '" & Request ("D3") &_
"', '" & Request ("D2") &_
"', '" & Word & ""
into_db = "INSERT into chat table (IP, name, color, expression, speech object, Speak) VALUES (" &_
SZ & ")"
Conn. Execute (into_db)
Conn. Close
End If
3, the user left
B5=request ("B5")
If b5= "Leave the chat room" Then if the user chooses to leave the chat room
Set conn=server.createobject ("ADODB. Connection ")
Connstr= "dbq=" +server.mappath ("Chat.mdb") + ";D river={microsoft Access DRIVER (*.mdb)};"
Conn.Open ConnStr removed him from the online list.
sql5= "Delete * from online user table WHERE name = '" & Request ("name") & ""
Conn. Execute (SQL5)
Name1=request ("name")
Sex1=request ("D4")
ming1= "Admin Announces" Administrator announces this user to leave
sz1= "<font size=5 color= #FF0000 ><strong>" & name1 & Sex1 & "have left in advance, welcome to come Again"
INTO_DB2 = "INSERT into chat table (name, Speak) VALUES (' & ming1 &" ', ' "& Sz1 &") "
Conn. Execute (INTO_DB2)
Conn.close
Response.Redirect "Chat.asp"
End If
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.