Important alert: (current site time 7/15/2013 11:10:19 PM EDT)
 

article

A Simple guestbook in ASP

Email
Submitted on: 8/25/2002 10:33:06 PM
By: Matthew Meadows 
Level: Beginner
User Rating: By 1 Users
Compatibility: ASP (Active Server Pages)
Views: 51944
(About the author)
 
     This article attempts to explain the basics of making an asp guestbook without the fuss and muss of string handling and giving you a small insight on active x data objects.

This article has accompanying files
 
 
Terms of Agreement:   
By using this article, you agree to the following terms...   
  1. You may use this article in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this article (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this article from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the article or article's description.
				Creating a guestbook in asp is actually quite easy...First off let me explain how to install this sample.....copy the asp files into the same directory and with front page drag the database into the explorer window of said html editor (i do it this way as it automatically sets the proper permissions on the fpdb directory for adding entries).
A brief explanation of the code:
there isn't much to the sign guestbook page other than it returns the current date/time when the page was accessed for a field in the database. the real work occurs in the guestadd.asp...i did this in two parts to a.) make it easier to read and b.) to not have to explain the use of hidden form fields to determine whether or not you should execute portions of code. mostly a though.
for those with little/no database/sql experience let me kind of explain the methods here...You first open a connection to a database...as you can tell it gives information on what type of database to expect and it's location in the web site (don't worry, if you uploaded like i said or have a friend that can set the permissions on that folder, you are golden...the db won't be downloaded). The connection object is used to open up your database for you (at least in this example, it's full uses are too numerous to mention in this article). the second part in dealing with the database comes with the adodb.recordset object...this is the object that actually interacts with your database...in the guestadd it will insert data, in the guestbook.asp page it will retrieve data...in the guestadd.asp i first open the recordset by calling the table name in the database i want...in this case, guests...i then call the addnew method and give it the array of fields i want to add, then the values i collected from the form (if you haven't read up on asp's intrinsic objects, i SERIOUSLY reccomend you do that before anything) and called an update method. it's as easy as that! then you close each object (in asp you don't really have to, the runtime will do that for you, but it's considered very good practice and considerate to resources) and dereferenced it (a fancy way of saying i don't need the memory for those objects anymore. again, not necessary, but good practice). If all goes well (and this should) the page will redirect you to the view guests page where you should see your entry listed. the listing page is very similar to the add page with one major exception. I did use sql on this one to specifically get fields from the database (i didn't want the gbID field and didn't feel like using an if statement to not print it). to paraphrase it's meaning, it's saying "i want the data for these fields in this table"....the recordset will retrieve it and put it in a handy dandy collection (a list of key/value pairs) for you to work with....from there we set up a simple loop that checks to see if the recordset is at the end, and if not to display a table with the fields i've asked for and again closes and dereferences the objects i've created to free up system resources....that's pretty much it. Again this is a simple guestbook, it has no field validation, or error handling involved with inputted user data, so there is room for improvement in that respect but this is the easiest way i've ever seen to implement a guestbook and it does incorporate principles that can be used in other dynamic html situations that involve data access. Hope this helps out! Cheers!

winzip iconDownload article

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. Afterdownloading it, you will need a program like Winzip to decompress it.Virus note:All files are scanned once-a-day by Planet Source Code for viruses, but new viruses come out every day, so no prevention program can catch 100% of them. For your own safety, please:
  1. Re-scan downloaded files using your personal virus checker before using it.
  2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

If you don't have a virus scanner, you can get one at many places on the net including:McAfee.com

 
Terms of Agreement:   
By using this article, you agree to the following terms...   
  1. You may use this article in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this article (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this article from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the article or article's description.

Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this article (in the Beginner category)?
(The article with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments
9/4/2002 3:08:46 AM

It's a pretty good code to show beginners how to create databaseconnections and how to add posts to a database. My own, and many others, opinion is that your should use pure SQL, instead of using recset.addnew and similar. There is also a lack of controlling the user input, and everyone can input html-commands and javascripts and those will be outputed to the page with no control. And one more thing, FrontPage is evil. You cant rely on FP to do your pages, everyone should learn how to write the code with tools like notepad. =)
(If this comment was disrespectful, please report it.)

 
9/4/2002 2:53:04 PMMatthew Meadows

to make this quick....frontpage was only used to connect to the web server and set folder permissions (if yer on 2k, why not?) form validation was already mentioned, and point taken on ado recordset addnew...was used as an easy example...and not used normally by me.
(If this comment was disrespectful, please report it.)

 
9/7/2002 9:13:57 AM

Ok Ok... i HATE articles that bla bla bla bla and then the author says that this is only for educational purposes only, and mention that they dont even use it... they use a saffer/better way of doing things... SO WHY waste our time with things that we dont even want to know? SHOW US the GOOD STUFF !!! Not what everyone already knows... We want to know the BEST way to do it... not just a lousy way to do it!
(If this comment was disrespectful, please report it.)

 
9/7/2002 9:15:17 AM

sorry for that... but i hate wasting my time reading only to find out that what i read it's not the best thing to do.
(If this comment was disrespectful, please report it.)

 
10/3/2002 9:21:33 AMJorgen Levesen

Was it possible to get the start of this ASP thing for us new ones ? F.ex. how to put this thing to work from start ?
I Get the error ADODB.Recordset error '800a0cb3'

Current Recordset does not support updating. This may be a limitation of the provider, or of the selected locktype.

/fpdb/guestadd.asp, line 33

Would very much appreciate any help.


(If this comment was disrespectful, please report it.)

 
4/10/2003 2:21:24 PMvnguyen

What's about this error message:
"An error occurred on the server when processing the URL. Please contact the system administrator."
(If this comment was disrespectful, please report it.)

 
5/31/2003 1:02:48 AM

Really the samples and its explanation
are fantastic.Easy to understand for the beginners
(If this comment was disrespectful, please report it.)

 
4/7/2005 12:48:02 PM

the code does not work
(If this comment was disrespectful, please report it.)

 
8/10/2005 6:50:05 PM

Error Type:
ADODB.Recordset (0x800A0CB3)
Object or provider is not capable of performing requested operation.
/simple/guestadd.asp, line 33

(If this comment was disrespectful, please report it.)

 
4/13/2008 9:12:43 AMAlbert Chesaro

This is a very nice piece of code. Good work.
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular article, please click here instead.)
 

To post feedback, first please login.