|
A Simple guestbook in ASP |
| | | | Submitted on: 8/25/2002 10:33:06 PM
By: Matthew Meadows
Level: Beginner User Rating:
By 1 Users Compatibility:ASP (Active Server Pages)
Users have accessed this article 3406 times. | (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! | | Download 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 Winzipto 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 | | | Your Vote! |
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.
=)
| 9/4/2002 2:53:04 PM:Matthew 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.
| 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!
| 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.
| 10/3/2002 9:21:33 AM:Jorgen 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.
| | Add Your Feedback! | Note:Not only will your feedback be posted, but an email will be sent to the code's author in your name.
NOTICE: The author of this article has been kind enough to share it with you. If you have a criticism, please state it politely or it will be deleted.
For feedback not related to this particular article, please click here. | | |