I am trying to create a chat room consisting of 2 pages, the index and the chat room. The index page allows you to login by giving a chat name to use during the session, the chatroom allows you to see the message and insert new messages. However it is not working and I can't figure out what the problem is. Please advice.
index.asp
<%@ language="VBScript"%>
<%
'code tuns when the form is submitted
'if Go is present then form has beed submitted
if not isempty(Request.Form("Go")) then
'connection is established
set MyConn = server.CreateObject("adodb.connection")
MyConn.Open ("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ="& Server.MapPath("\nvillare\db\nidia.mdb"))
'session variable chatname is set to name supplied by user
Session("ChatName") = Request.Form("ChatName")
'text of thread is set to an empty string
Session("Thread") = ""
set RSLastEntry = MyConn.Execute("select Max(ChatID) as MaxID from ChatRoom")
'checks to see the last entry in the dbs
'if none then it is set to 0
if isnumeric(RSLastEntry("MaxID")) then
Session("LastEntry") = RSLastEntry("MaxID")
else
Session("LastEntry") = 0
end if
'user is directed to the chat page
Response.Redirect "./chat.html"
end if
%>
chat.html consists of body.asp and footer.asp
body.asp
<% Language=VBScript%>
<%
'connection to the dbs to retrieve any new threads
set MyConn = server.CreateObject("adodb.connection")
MyConn.Open ("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ="& Server.MapPath("\nvillare\db\nidia.mdb"))
'retrieve any new entries entered after the last entry was received
set RSMessage = MyConn.Execute("select ChatID, Message from ChatRoom where " _
& "ChatID > " & Session("LastEntry"))
'code loops through each record
do until RSMessage.EOF
'append new message to the current thread
Session("Thread") = Session("Thread") & RSMessage("Message") &
chr(13)
'next time page refreshes it will not grab the old message
Session("LastEntry") = RSMessage("ChatID")
RSMessage.MoveNext
Loop
%>
footer.asp
<%@ Language=VBScript %>
<%
'checks to see if the button has been pressed
if not isempty("Request.Form("addMessage")) then
'if it has been pressed then it will connect to the dbs
set MyConn = server.CreateObject("adodb.connection")
MyConn.Open ("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ="& Server.MapPath("\nvillare\db\nidia.mdb"))
'the message is added to the dbs
MyConn.Execute "insert into ChatRoom (WhenEntered, Message) values
(" _
& "'" & Now & "', " _
& "'" & Session("ChatName") & ": " & Request.Form("txtMessage") & "')"
'page is refreshed by redirecting to the chat page
Response.Redirect "./chat.html"
end if
%>
Thanks for your help!!
Nidia