% response.buffer=true %>
<%
'declaring all database variables and opening connections
Set dc = Server.CreateObject("ADODB.Connection")
Set rs = Server.CreateObject("ADODB.Recordset")
dc.Open "DBQ=" & Server.Mappath("database") & ";Driver={Microsoft Access Driver (*.mdb)};"
%>
<%
' this script adds a record to database
openMethod = request.form ("openMethod")
if openMethod = "postMessage" then 'this line checks if the ASP file should post a message
USER_DATE = FormatDateTime(NOW) 'records the post date and time
USER_NAME = request.Form ("USER_NAME")
USER_CITY = request.Form ("USER_CITY")
USER_MAIL = request.Form ("USER_MAIL")
USER_URL = request.Form ("USER_URL")
USER_MESSAGE = request.Form ("USER_MESSAGE")
if (USER_NAME = "" or USER_MESSAGE = "" or USER_MAIL = "") then
response.write ("NAME, MAIL and MESSAGE fields must be filled!
") & VBCRLF
End IF
if USER_CITY = "" then USER_CITY = "nowhere" End If
if USER_URL = "" then USER_URL = "none" End If
if len(USER_MESSAGE) > 4096 then USER_MESSAGE = Left(USER_MESSAGE, 4096) End If 'this sets the message size limit to 4 kb: if it's more then 4kb, a part of it will be erased
if USER_URL <> "" then if Left(UCase(USER_URL),7) <> "HTTP://" then USER_URL = "http://" & USER_URL End IF 'if user writes his url as "www.someurl.com" then it's replaced with "http://www.someurl.com"
MYSQL = "SELECT GBOOK.* FROM GBOOK" 'selects the guestbook table in the database
if NOT (USER_NAME = "" or USER_MESSAGE = "" or USER_MAIL = "") then 'if all fields are valid, adds a record to the DB
rs.Open MYSQL, dc, 1, 3 'opens the database
rs.AddNew
rs.Fields("USER_DATE") = USER_DATE
rs.Fields("USER_NAME") = USER_NAME
rs.Fields("USER_CITY") = USER_CITY
rs.Fields("USER_MAIL") = USER_MAIL
rs.Fields("USER_URL") = USER_URL
rs.Fields("USER_MESSAGE") = USER_MESSAGE
rs.Update
'this code saves your name, mail, url and city as a cookie,
' so that users don't have to enter them the next time they use the guestbook
response.Cookies("server")("name") = USER_NAME
response.Cookies("server")("email") = USER_MAIL
response.Cookies("server")("URL") = USER_URL
response.Cookies("server")("city") = USER_CITY
response.Cookies("server").Expires = DateAdd("m",1,Date)
response.redirect ("guestbook.asp") 'redirects to the guestbook page
End If
End If
%>
Pages: <% if NOT pagePrev < 1 then %>>Prev <% else %> Prev <% End If %> | <% While NOT pageNumber = Pages pageNumber = pageNumber + 1 %> <% if CInt (pageNumber) = CInt (currentPage) then %> <% = pageNumber %> | <% else %> > <% = pageNumber %> | <% End If %> <% Wend %> <% if NOT pages < pageNext then %> >Next <% else %> Next <% End If %> | Total entries: <% = Records %> |
Name: <%= rs("USER_NAME") %>, City: <%= rs("USER_CITY") %> E-mail: ><%= rs("USER_MAIL")%> URL: ><%= rs("USER_URL") %> |
Posted: <%= rs("USER_DATE") %> |
Message: <%= rs("USER_MESSAGE") %>
<% rs.MoveNext Loop else response.write ("No records found, be the first to post a comment!
") & VBCRLF
End If
%>
<%
'closing connections and resetting all database variables
rs.Close
Set rs = Nothing
dc.Close
Set dc = Nothing
%>