Bytes Expert Newtork: Connect with experts in IT / Business | Expert Topics



Search


Go Back   Programmers Resource > Code Section > ASP Articles
User Name
Password


 
 
Thread Tools Search this Thread Rating: Thread Rating: 346 votes, 4.98 average. Display Modes
  #1  
Old 06-13-2003, 02:59 PM
admin admin is offline
Administrator
 
Join Date: May 2003
Posts: 116
Creating a Guestbook in ASP

ASP Guestbook, of course a simple database can be constructed using following:

*******************
Database name: guests.mdb
Table name: guestbook
Field names:
name
email
url
message
********************


This is my first guestbook. The code is original - and I hope simple and straightforward. The first file is alled "guestbook.asp" and is the form the user sees to enter his/her message to the guestbook. If you examine this file, you will see that this form is sent to another ASP page (or script) called "guestbookThankYou.asp".

I have used a simple javascript script for the button which - when clicked - sends the user to the "guests.asp" page - which displays the guestbook entries. I have tested this script and it works great - http://www.dodgecountyclassifieds.c...k/guestbook.asp - check it out!

* NOTE: Of course, you may need to modify the path for the database, place database in your \db directory.

guestbook.asp

PHP Code:
 <html>
<
head>
<
title>ASP Guestbook</title>
</
head>
<
body>

<
font face="ARIAL" size="2" color="BLACK"><b>
Welcome to my guestbook...</b></font></p>
<
FORM METHOD="POST" ACTION="guestbookThankYou.asp">
Name: <INPUT NAME="name" size="33"><br>
Email: <INPUT NAME="email" size="33"><br>
URL: <INPUT NAME="url" size="33"><br>
Message: <textarea rows="6" name="message" cols="30">
        </
textarea><br>
<
INPUT TYPE="SUBMIT" VALUE="SEND">
<
INPUT TYPE="BUTTON" VALUE="VIEW GUESTBOOK" 
       
onClick="location.href='guests.asp';">
</
form>
</
body>
</
html


guestbookThankYou.asp

PHP Code:
 <html>
<
head>
</
head>
<
body>

<
p>Thank you for signing my guestbook...</p>
<
FORM METHOD="POST" ACTION="guests.asp">
<%
Set cn Server.CreateObject("ADODB.Connection")
openStr "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" Server.MapPath("\db\guests.mdb")
cn.Open openStr
SQL 
"SELECT * FROM guestbook"
Set record Server.CreateObject("ADODB.Recordset")
record.Open sqlcn22
record
.AddNew
record
("name") = Request.Form("name")
record("email") = Request.Form("email")
record("url") = Request.Form("url")
record("message") = Request.Form("message")
record("todaysDate") = Now()
record.Update
record
.Close
Set record 
Nothing
cn
.Close
Set cn 
Nothing

%>
<
INPUT TYPE="BUTTON" VALUE="VIEW GUESTBOOK" 
       
onClick="location.href='guests.asp';">
</
form>
</
body>
</
html


guests.asp

PHP Code:
 <html>
<
head>
</
head>
<
body>

<
p>Guestlist entries....</p>
<%
openStr "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" Server.MapPath("\db\guests.mdb")
Set cn Server.CreateObject("ADODB.Connection")
cn.Open openStrUserIDPassword
SQL 
"SELECT * FROM guestbook ORDER BY 'ID' DESC"
Set record Server.CreateObject("ADODB.Recordset")
record.Open sqlcn
record
.MoveFirst
Do While Not record.EOF
     Response
.Write"<b>Date</b>: " record("todaysDate").Value "<br>"
     
Response.Write"<b>Name</b>: " record("name").Value "<br>"
     
emailValue=record("email").Value
     Response
.Write"<b>Email: </b>" _
     
"<A HREF='mailto:" emailValue "'>" emailValue "</A><br>"
     
urlValue=record("url").Value
     Response
.Write"<b>URL: </b><A HREF='" _
     urlValue 
"' target='blank'>" urlValue "</A><br>"
     
Response.Write"<b>Message</b>: " _
     record
("message").Value "<br>"
     
Response.Write"<hr width='80%'>"
     
record.MoveNext
Loop

record
.Close
Set record 
Nothing
cn
.Close
Set cn 
Nothing
%>

</
body>
</
html


By Chris Perry
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump



All times are GMT -5. The time now is 02:37 AM.



Powered by: vBulletin Version 3.0.3
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
All content Copyright ©1999 - 2010, Programmers Resource, unless otherwise noted.