When you think ASP, think...
Recent Articles
All Articles
ASP.NET Articles
Message Board
Related Web Technologies
User Tips!
Coding Tips

Sample Chapters
Commonly Asked Message Board Questions
JavaScript Tutorials
MSDN Communities Hub
Official Docs
Stump the SQL Guru!
XML Info
Author an Article
ASP ASP.NET ASP FAQs Message Board Feedback
Print this page.
Published: Wednesday, May 12, 1999

Creating a Guestbook with ASP
By Joao Vieira

I Know that there's lot of GuestBooks around, but I think that one more won't be too much. And you can see this one working on my site at http://www.joaovieira.com

- continued -

To set up the guestbook, we will need to do the following two things:

1. Create a database with the following structure:


2.) Write the code! :)

FILE: Guestbook.asp
This is the only file...... that will make you have an easy guestbook at your site.....

    'the name of the sender
    Dim cxname 

    'the user's email
    Dim cxemail

    'and the guestbook message!
    Dim cxmessage

    'Used for error control...
    'If OK = 1, no errors.
    'If OK = 0, there are errors!
    Dim OK

    Set Conn = Server.CreateObject("ADODB.Connection")

    'I created a DSN named guestbook which points to
    'the database we created with the structure outlined above
    Conn.open "DSN=guestdb;" 

    Set rs = Server.CreateObject("ADODB.Recordset") 

    OK = 1
    ' You can see my article about e-mail validation
    ' to better understand this lines bellow
    If Len(Request.form("cxemail")) > 0 and Len(Request.form("cxemail")) < 5 Then
       OK = 0
       If InStr(1, Request.form("cxemail"), "@", 1) < 2 Then
          OK = 0
          If InStr(1,Request.form("cxemail"), ".", 1) < 4 Then
             OK = 0
          End If
       End If
    End If

    ' Make sure the name isn't blank...
    If len(Request.form("cxname")) < 1 then 
      OK = 0
    end if   

    'Make sure the message isn't blank
    if len(Request.form("cxmensagem")) <= 8 then 
      OK = 0
    end if

    ' if there is no errors let's put it in the DB
    if OK = 1 then 
       Set rs2 = Server.CreateObject("ADODB.Recordset")
       SQLStmt = "SELECT * FROM guestbook"
       rs2.Open SQLstmt,Conn,1,2
       rs2("nameAs") = Request.form("cxname")
       ' I get the data thats within
       ' You can see my article 4 Ways To Pass Info between ASP Files

       rs2("email") = Request.form("cxemail")
       rs2("message") = Request.form("cxmessage")
       rs2("date") = month(now) & "/" & day(now) & "/" & year(now)

    end if

     SQLStmt = "SELECT * FROM guestbook ORDER BY id DESC"

     rs.Open SQLstmt,Conn,1,2

<!-- No this is only the code you will have on your page-->

<img src="images/tguestbook.jpg" width="150" height="38"></p>
<div align="center"><center>
   <table border="0" width="90%">
      <td width="100%">
     <div align="center">
     <table border="0" width="90%">
     'at this time we will put all the messages entered in 
        'the table
     While Not rs.EOF
             <td width="100%" bgcolor="#000080">
          <font face="Arial" color="#E7F4D8">
                <strong>Posted in </strong></font>
          <big><font color="#00FF00"><em>
                <font face="Arial" color="#E7F4D8">
          <strong>sent by</strong></font>
          <font color="#00FF00"><em>
          <a href="mailto:<%=rs("email")%>"><big>

          <div align="center"><center>
                <table border="0" width="70%">
                     <td width="100%"><p align="center">
                      <font color="#FFFF80" face="Arial">



    <% 'everything is done ... so lets clean the fields in the form

    <form name="gbsend" method="POST" action="guestbook.asp">
       <p><font face="Arial"><strong>
       <font color="#E7F4D8">Name :</font>
       <input type="text" name="cxname" value="<%=cxname%>" size="20">
       <font face="Arial" color="#E7F4D8">
       <strong>E-Mail : </strong></font>
       <input type="text" name="cxemail" value="<%=cxemail%>" size="20">
       <font face="Arial" color="#E7F4D8"><strong<br> 
       Message :<br></strong></font>
       <textarea rows="3" name="cxmessage"
          value="<%=cxmessage%>" cols="38">
       <input type="submit" value="   Sign   " name="B1">
       <input type="reset" value=" Reset " name="B2">

I think it isn't too hard, but I hope it will help you with your GuestBook.....

João Vieira BIO: (email me!)
- Age : 23
- Student And worker (tryin' to finish university, on the last year of the graduation)
- Workin' now at NetGate Portugal
- Programming little stuff since 1989
- Programming HTML since 1996
- Programming JavaScript since 1997, made some experiences with Java.
- Programming ASPs since the Summer of 1997 (yeap, I didn't had nothing to do. Now I love it.)
- Programming ActiveX since 1998
- Webmaster of www.joaovieira.com

ASP.NET [1.x] [2.0] | ASPFAQs.com | Advertise | Feedback | Author an Article