Submitted on: 8/12/2002 7:30:40 AM By: As absurd as it sounds, we have to give a name...
Level: Beginner User Rating:
By 1 Users Compatibility:PHP 3.0, PHP 4.0
This will show you how to create a simple guestbook in PHP.
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.
Section 1: Why I made it
I wanted a guestbook for my website but the server didn't support mySQL. So I made this. (It's not very good because I only started learning PHP last week).
Section 2: The HTML
Create an HTML file called anything you like (I called mine form.html). It should have something like this in it:
Guestbook
Section 3: The PHP
Make a PHP file called process.php and write the following:
$store = "store.dat";
if ($action == add) {
echo "Thankyou $name, Your message has been submitted
");
fclose($opener);
echo "To view the messages, click here";
} else if ($action == view) {
$table = join('', file($store));
echo "$table";
} else if ($action == clear) {
$opener = fopen($store,"w");
fputs($opener, "");
fclose($opener);
echo "Table cleared";
}
?>
Section 4: The DAT File
Create an empty file called store.dat. Thats it!
Section 5: Uploading and Enjoying
Upload the three files and CHMOD the DAT to 666 (-rw-rw-rw)(read all write all).
If you go to process.php?action=view, then you will be able to view the guestbook. If you go to process.php?action=clear, you will clear the guestbook.
Hope you enjoy it!
8/13/2002 6:58:26 PM:Horacio The code is not working...
when I hit
submit, it gives me some errors in the
process.php file.
Error: Undefined
variable: action
Maybe someone can
look at the code and post it again?
8/14/2002 5:54:12 PM:Charles Chadwick Well, just by looking at it, although I
could be wrong, where it says
if
($action == clear)
clear should be
in quotes, such as
if ($action ==
"clear")
same with $action == view
and $action == add. I myself got a
different error, "parse error,
unexpected $". I'll see if I can get it
working. A valiant effort none the less
by the author.
8/16/2002 5:51:19 AM:As absurd as it sounds, we have to give a name... Horacio, I forgot to include a line of
script that is very important. You need
to add a: <input type=hidden
name=action value=add>
Sorry!
Charles, yes, you can use
quotes but it is not essential. I'm not
sure about the error - I'll try and
work it out.
8/21/2002 10:38:42 PM:HellOnComputer a few little tweaks and it wouldnt be
too bad. (try <br> instead of pressing
enter in echo)
8/23/2002 5:32:00 AM:mike ive never done php before what do you
mean by CHMOD the DAT to 666
(-rw-rw-rw)(read all write all).????
8/23/2002 2:43:24 PM:Charles Chadwick chmod is setting file permissions on a
unix/linux machine. I suggest doing a
search on google for how to do that,
there's probably a better explanation
of it somewhere on the net than I can
provide here.
9/3/2002 4:53:01 AM: great! this was just what i was looking
for, simple and working! add a few
html- tags to the proess.php file and
you can make your own style gb. love it!
9/13/2002 4:17:45 PM:Darryl Porter This is a good an simple script. In
reference to the comment above, quote
are not needed in the "if statements"
if the server running the script is on
a Unix based system. However, Window
Based Operating systems aren't as
forgiving. You will need to put either
single or double quotes in else you
will receive an error. It is a good
idea to put them in anyway--it makes
for clean cross-platform codes.
10/4/2002 10:49:05 AM: does not work, i get a load of c rap
when i press submit, it looks like its
showing all the php code, when i add a
<?php tag to the PHP file, it shows
BLANK.
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.