dcsimg

A GuestBook With only One ASP file

By ServerWatch Staff (Send Email)
Posted Jun 28, 1999


Joco 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 www.joaovieira.com

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 www.joaovieira.com

1.Lets start with the DataBase

The structure of the DataBase  :

guestbook(id As Autonumber, data As Date/Time, nomeAs Text , email As Text, message As Text)

(ex: table(field1 As type, field2 As type) )

So, let's get started with the code......

 

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

<%
     Dim cxnome ' the variable of the name of the sender
     Dim cxemail ' the variable of the email
     Dim cxmensagem ' and the variable of the message
     Dim OK     ' the one I use to control errors 1 Ok,  0 theres errors....

     Set Conn = Server.CreateObject("ADODB.Connection")
     Conn.open "DSN=guestdb;" ' I used the guestdb DSN
    

     Set rs = Server.CreateObject("ADODB.Recordset") 
     OK = 1
     
     ' You can see my article about e-mail validation , and understand this lines bellow
     If Len(Request.form("cxemail")) > 0 and Len(Request.form("cxemail")) < 5 Then
		OK = 0
		Else
		   If InStr(1, Request.form("cxemail"), "@", 1) < 2 Then
			 OK = 0
		     Else
			   If InStr(1,Request.form("cxemail"), ".", 1) < 4 Then
					OK = 0
		       End If
			 End If
	End If
	
   if len(Request.form("cxnome")) < 1 then ' I control the name, to ensure it isn't blank
      OK = 0
   end if   
   if len(Request.form("cxmensagem"))<= 8 then ' and do it with the message too
      OK = 0
   end if
 
  if OK = 1 then ' if there is no errors lets put it in the DB
                Set rs2 = Server.CreateObject("ADODB.Recordset")
		SQLStmt = "SELECT * FROM guestbook"
		rs2.Open SQLstmt,Conn,1,2
		rs2.AddNew
		rs2("nome") = Request.form("cxnome") ' I get the data thats within
                'can see my article the 4 Ways To Pass Info between ASP Files
		rs2("email") = Request.form("cxemail")
		rs2("mensagem") = Request.form("cxmensagem")
		rs2("data") = day(now) & "/" & month(now) & "/" & year(now)
                ' I have formated the date in the way we use more here in Portugal
		rs2.Update
		rs2.Close   
   end if
     
     SQLStmt = "SELECT * FROM guestbook ORDER BY id DESC" ' my SQL statement 
     ' I made this order so the last to send will be the one one the top...and so..
     rs.Open SQLstmt,Conn,1,2
%>
<html>
<head>
<title>GuestBook</title>
</head><!-- No this is only the code you will have on your page-->
<body BGCOLOR="#385FC6" TEXT="#000000" LINK="#0000FF" ALINK="#FF0000" VLINK="#400040">
<p><img src="images/tguestbook.jpg" width="150" height="38"></p>
<div align="center"><center>
<table border="0" width="90%">
  <tr>
    <td width="100%"><div align="center"><center><table border="0" width="90%">
      <%While Not rs.EOF ' at this time we will put all the messages entered in 
                          '  the table%>
      <tr>        
        <td width="100%" bgcolor="#000080"><font face="Arial" color="#E7F4D8">
<strong>Posted in </strong></font><big><font
        color="#00FF00"><em><%=rs("data")%>&nbsp;&nbsp;&nbsp; </em></font></big>
<font face="Arial"
        color="#E7F4D8"><strong>sent by&nbsp; </strong></font><font color="#00FF00"><em><a
        href="mailto:<%=rs("email")%>"><big><%=rs("nome")%></big></a><br>
        </em></font><div align="center"><center><table border="0" width="70%">
          <tr>
            <td width="100%"><p align="center"><font color="#FFFF80" face="Arial">
<strong><%=rs("mensagem")%></strong></font></td>
          </tr>
        </table>
        </center></div></td>
        </tr>
        <%
          rs.MoveNext 
        wend
        rs.close%>
    </table>
    </center></div></td>
  </tr>
</table>
</center></div>
<% 'everything is done ... so lets clean the fields in the form
     cxnome=""
     cxemail=""
     cxmensagem=""
%>
<form name="gbsend" method="POST" action="guestbook.asp">
  <p><font face="Arial"><strong>
  <font color="#E7F4D8">&nbsp; Name :</font> </strong></font>
  <input type="text" name="cxnome" value="<%=cxnome%>" size="20"><br>
  <br>
  <font face="Arial" color="#E7F4D8">
  <strong>&nbsp; E-Mail : </strong></font>
  <input type="text" name="cxemail" value="<%=cxemail%>" size="20"><br>
  <font face="Arial" color="#E7F4D8"><strong><br>&nbsp; 
  Message :<br></strong></font>
  <textarea rows="3" name="cxmensagem" value="<%=cxmensagem%>" cols="38"></textarea></p>
  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  <input type="submit" value="   Sign   " name="B1">
<input type="reset" value=" Reset " name="B2"></p>
</form>
</body>
</html>
I think it isn't too hard, but I hope it will help you with your GuestBook.....

Page 1 of 1


Comment and Contribute

Your name/nickname

Your email

(Maximum characters: 1200). You have characters left.


 

 


Thanks for your registration, follow us on our social networks to keep up-to-date