If Request("name")="" or Request("pass")="" Then 判斷使用者名稱與密碼是否為空白
a="名字或密碼不可為空!<br>" 如果為空白,則定義此錯誤變數
Response.Redirect "chatadd1.asp?a=" & a & " " 錯誤一旦出現立即返回登陸介面
end if
Set Conn=Server.CreateObject("ADODB.Connection") 如果客戶輸入非空,則開始查詢資料庫
Connstr="DBQ="+server.mappath("chat.mdb")+";DRIVER={Microsoft Access Driver (*.mdb)};"
Conn.Open connstr
sql="SELECT * FROM 使用者表 WHERE 姓名='" & Request("name") & "'" 查看資料庫中是否存在這個使用者
Set Rs=conn.Execute(sql)
If Rs.Bof OR Rs.Eof Then 如果資料庫中還沒有這個使用者,則
sz = "'" & Request("IP") &_ 把該使用者寫入使用者資料庫
"', '"& Request("name") &_
"', '"& Request("D4") &_
"', '"& Request("pass") & "'"
into_db = "INSERT INTO 使用者表 ( IP, 姓名, 性別, 密碼 ) VALUES(" &_ 寫入使用者資料庫
sz & ")"
conn.Execute(into_db)
Else 如果資料庫中已經存在這個使用者,則
If Request("pass")<>Rs("密碼") Then 查看他的密碼是否正確。
a="這個名字已經被別人使用,或者你輸入的口令不對!<br>" 如果密碼錯誤則定義錯誤資訊
Response.Redirect "chatadd1.asp?a=" & a & " " 立即返回登陸介面並返回此錯誤資訊
end if
end if
time1=now 如果登陸表單沒有任何錯誤,則開始成為線上使用者並進入聊天
Set Conn=Server.CreateObject("ADODB.Connection")
Connstr="DBQ="+server.mappath("chat.mdb")+";DRIVER={Microsoft Access Driver (*.mdb)};"
Conn.Open connstr
sql="SELECT * FROM 線上使用者表 WHERE 姓名='" & Request("name") & "'" 查看線上名單中是否存在這個使用者
Set Rs=conn.Execute(sql)
If Rs.Bof OR Rs.Eof Then 如果線上名單中的確沒有這個使用者,則
sz = "'" & Request("name") &_ 在線上使用者表中添加這個使用者
"', '"& Request("D4") &_
"', '"& time1 & "'"
into_db = "INSERT INTO 線上使用者表 ( 姓名, 性別, 登陸時間 ) VALUES(" &_ 添加這個使用者
sz & ")"
conn.Execute(into_db)
name=Request("name")
sex=Request("D4")
ming="管理員宣布" 管理員開始宣布歡迎這位(先生/女士)的光臨
sz="<font size=5 color=#FF0000><strong>" & "熱烈歡迎" & name & sex & "的光臨"
into_db2 = "INSERT INTO 聊天表 ( 姓名,說話 ) VALUES('" & ming & "','" & sz & "')"
conn.Execute(into_db2)
<%
B3=Request("B3")
If B3="發言" Then 準備把使用者發言寫到聊天表中
Set Conn=Server.CreateObject("ADODB.Connection")
Connstr="DBQ="+server.mappath("chat.mdb")+";DRIVER={Microsoft Access Driver (*.mdb)};"
Conn.Open connstr
%>
<%
word=Request("word")
if Request("word")="" then 如果什麼都沒寫就發言,則預設發言為兩眼開開,正在發獃
word="兩眼開開,正在發獃....."
end if
%>
B5=Request("B5")
If B5="離開聊天室" Then 如果使用者選擇離開聊天室則
Set Conn=Server.CreateObject("ADODB.Connection")
Connstr="DBQ="+server.mappath("chat.mdb")+";DRIVER={Microsoft Access Driver (*.mdb)};"
Conn.Open connstr 從線上名單中把他刪除
sql5="delete * FROM 線上使用者表 WHERE 姓名='" & Request("name") & "'"
conn.Execute(sql5)