GuidesA GuestBook With only One ASP file

A GuestBook With only One ASP file




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")) 
    
   if len(Request.form("cxnome")) 
    
  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
%>

GuestBook



Posted in
   
sent by  <a href="mailto:">



  Name :

<input type="text" name="cxnome" value="” size=”20″>


  E-Mail :

<input type="text" name="cxemail" value="” size=”20″>

 
Message :

<textarea rows="3" name="cxmensagem" value="” cols=”38″>

           
         
            

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

Latest Posts

Related Stories