I am trying to create a basic chat room and am having much difficulty. Can anyone please help?
Code:
<%@ language="VBScript"%>
<%
'if form has not been submitted it will ask you to enter a chat name
if isempty(Request.Form("OK")) then
theMessage1 = "Enter the name you would like to go by during this chat:"
else
'code runs when the form is submitted
'check if chat name has been entered
if isempty (Request.Form("chatName")) or Request.Form("chatName") = "" then
theMessage1 = "Please enter a Chat Name."
else
'connection is established
'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.htm"
end if
end if
%>
<html>
<head>
<title>Live Chat Room</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<center><span class="top"><b>Welcome to the Chat Room</b></span>
</center><p>
<form action="../../private/chatRoom/index.asp" method="post">
<p class="btext">
<% Response.Write theMessage1 %><p>
<input type="text" name="chatName" size="25" maxlength="22"><p>
<input type="submit" value="OK" name="OK">
</form>
</body>
</html>
chat.htm is a frameset with two frames
body.asp --
<%@ Language=VBScript %>
<%
'connection included to the db, retrieve any new threads
'retrieve any new entries entered after the last entry was received
set RSMessage = Server.CreateObject("ADODB.Recordset")
MySQL = "SELECT ChatID, Message FROM ChatRoom WHERE ChatID > " & Session("LastEntry")
RSMessage.Open MySQL, conn
'code loops through each record
while RSMessage.Eof = false
'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
wend
%>
<html>
<head>
<title>Body for the Chat Room</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="refresh" content="15">
</head>
<body>
<p><span class="otext"><b>Chat Window</b></span><p>
<textarea rows=13 cols=70 name="chatWindow" WRAP=VIRTUAL readonly>
<% Response.Write Session("Thread") %></textarea>
</body>
</html>
and footer.asp --
<%@ Language=VBScript %>
<%
if isempty(Request.Form("Submit")) then
'initial message to the user
'listed in html part
TheMessage1 = "Please use the form below to sign the guestbook."
TheMessage2 = "Note that fields with *** are required."
TheMessage3 = ""
else
'temporary variables to hold the data
theName = Request.Form("theName")
Email = Request.Form("Email")
Location = Request.Form("Location")
Comments = Request.Form("Comments")
'check validation of Name
if isempty (Request.Form("theName")) or Request.Form("theName") = "" then
TheMessage1 = "The form was not submitted."
TheMessage2 = "Name is required!"
'check validation of email
elseif isempty(Request.Form("Email")) or Request.Form("Email") = "" then
TheMessage1 = "The form was not submitted."
TheMessage2 = "Email Address is required!"
elseif instr(Request.Form("Email"), "@") = 0 or instr(Request.Form("Email"), ".") = 0 then
TheMessage1 = "The form was not submitted."
TheMessage2 = "Email address is invalid!"
else
'form has been submitted
'send info to database
TheMessage1 = "Thanks " & theName & " for signing my book"
TheMessage2 = "Your entry will be reviewed prior to posting."
TheMessage3 = "<a href='guestBook.asp'>View the Guestbook</a> " & " || " & " <a href='signBook.asp'>Return Home</a>"
'combine the message to send to my email address
'EmailMessage = "Sign-In entry to be reviewed for posting:" & chr(13) & chr(13)
'13 creates a new line in the message
'EmailMessage = EmailMessage & "Name: " & theName & chr(13)
'EmailMessage = EmailMessage & "Email Address: " & Email & chr(13)
'EmailMessage = EmailMessage & "Location: " & Location & chr(13)
'EmailMessage = EmailMessage & "Comments: " & Comments & chr(13)
'set connection to email the message
'set objMail = CreateObject("CDONTS.NewMail")
'send message to my email address
'parameter is to who, from, subject, message
'objMail.Send "
[email protected]", Request.Form("Email"), _
'"New Entry into the GuestBook!", cstr(EmailMessage)
'destroy the objMail
'set objMail = nothing
'insert data into the database
dim MySQL
MySQL = "INSERT INTO SignIn (theDate, theName, Email, Location, Comments)"
MySQL = MySQL & " VALUES ('" & Date() & "','"
MySQL = MySQL & theName &"','"
MySQL = MySQL & Email &"','"
MySQl = MySQL & Location &"','"
MySQL = MySQL & Comments &"')"
conn.Execute(MySQL)
end if
end if
%>
<html>
<head>
<title>Sign Guest Book</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body><center>
<% Response.Write TheMessage1 %><br>
<% Response.Write TheMessage2 %><p>
<% Response.Write TheMessage3 %></center>
<% if TheMessage1 <> "Thanks " & theName & " for signing my book" then%>
<p>
<form method="post" action="signBook.asp" name="sign">
<table align="center" width="65%" border="0" bordercolor="#CC9900" cellspacing="6" cellpadding="10">
<tr>
<td width="35%">Name:***</td>
<td><input type="text" name="theName" value="<%= theName %>" size="30" maxlength="28"></td>
</tr>
<tr>
<td>E-mail Address:***</td>
<td><input type="text" name="Email" value="<%= Email %>" size="30" maxlength="28"></td>
</tr>
<tr>
<td>Location:</td>
<td><input type="text" name="Location" value="<%= Location %>" size="30" maxlength="28"></td>
</tr>
<tr>
<td valign="top">Comments:</td>
<td align="left"><textarea rows="4" cols="40" name="Comments" value="<%= Comments %>"></textarea></td>
</tr>
<tr>
<td colspan=2><center><input type="submit" value="Submit" name="Submit"></center></td>
</tr>
</table>
</form>
<% end if %>
</body>
</html>
Any help is greatly appreciated!!
Thanks!
nvillare