We hope you enjoy your visit.

You're currently viewing our forum as a guest. This means you are limited to certain areas of the board and there are some features you can't use. If you join our community, you'll be able to access member-only sections, and use many member-only features such as customizing your profile, sending personal messages, and voting in polls. Registration is simple, fast, and completely free.


Join our community!


If you're already a member please log in to your account to access all of our features:

Username:   Password:
Add Reply
Simple Guestbook; The PHP Script
Topic Started: Apr 9 2005, 06:08 PM (597 Views)
shockwave-
My other title is a Ferrari
[ *  * ]
Does anyone have a good script, or link to a script for a simple guestbook? I have avalible installations, but I want to have guestbooks on many different pages, not just one (like reviewing an article). I don't know anything about MySQL, and I don't want people to log in. :unsure:

Remember, pretty simple, just a name and a message and it displays it on the page that the form is on. Thanks.
Offline Profile Quote Post Goto Top
 
Jory
Member Avatar
Member
[ *  *  *  *  *  * ]
Code: HTML
 
<?php
if(isset($_POST["name"]) && isset($_POST["title"]) && isset($_POST["message"])){
$name = $_POST["name"];
$datafile = "file-to-put-it-in.txt";
$pointer = fopen($datafile,"r+");
$oldmessage = fread($pointer,filesize($datafile));
$message = $_POST["message"];
$message = htmlspecialchars($message);
$message = stripslashes(nl2br($message));
$day = date("j.n.Y");
$wrighter = "bY: <B> $name</B>, on $day";
$titel = "<h1>Titel: " . $_POST["title"] . "</h1>";
rewind($pointer);
fputs($pointer,"$title\n$wrighter<BR>\n$message\n$oldmessage\n");
}
else
{ ?>
<form action="<?php echo $_SERVER[PHP_SELF]; ?>" method="POST">
Name:<br>
<input type="text" name="name" size="33"><br>
Title:<br>
<input type="text" name="title" size="33"><br>
Bericht:<br>
<textarea name="message" rows="10" cols="40"></textarea><br>
<input type="submit" value="Post News">
</form>
<?php
}
?>


This should do it.
(I think.
Changed it a bit from what I use, so.)

If you don't want the title to be <h1>, you should put an <br> at the end of $message.

(Like this, new messages get put on top.
fputs($pointer,"$title\n$wrighter<BR>\n$oldmessage\n$message\n");
this will put new messages at the bottom.
)


Hope this helps you :)
Offline Profile Quote Post Goto Top
 
shockwave-
My other title is a Ferrari
[ *  * ]
Thanks. First, I had some troubles, then I CHMODDED, and got it to work. Thanks for the code Qj. ;)


Crap, :/ Now, I got it to write on the page, but it posts on top of the submit box. I want it to post Below the forms. Any suggestions?
Offline Profile Quote Post Goto Top
 
Jory
Member Avatar
Member
[ *  *  *  *  *  * ]
What is the code you are using exactly?

(There is no line in the script I gave you that reads the .txt file.)
Offline Profile Quote Post Goto Top
 
shockwave-
My other title is a Ferrari
[ *  * ]
Great, got it working. Thanks.
Offline Profile Quote Post Goto Top
 
Undead
Member
[ *  * ]
Can somone tell me what this code actually does?
Offline Profile Quote Post Goto Top
 
Jory
Member Avatar
Member
[ *  *  *  *  *  * ]
What version do you wanna read?

Long version:
First, it checkes if $_POST["name"] etc. are filled in.
If not, it will dislay the fill-in form.
( <form> to </form> )
If they are set, it will open the .txt file where you want the messages put in.
$pointer = fopen($datafile,"r+")
means that when using $pointer, the file will be opend with read/write rights.
Then, it puts all the text in the file in $oldmessage (the $oldmessage = fread($pointer,filesize($datafile)); line does that)
Then it puts the message you enterd in $message, the lines under that are for taking out double spaces, special characters, etc.
Then it sets the current date to $day, then the name you filled in ($name) and the date to $wrighter ($wrighter has some stuff for making it look nice in it two).
Then puts $pointer (which opens the file) to the begin of the file.
fputs($pointer,"$title\n$wrighter<BR>\n$message\n$oldmessage\n");
that line puts alle the stuff in the .txt file.

Short version:
It takes the stuff you fil in into the form and puts that stuff in a .txt file.
Offline Profile Quote Post Goto Top
 
lordshaun
join my forum :D
[ *  * ]
wow the code looks confusing
Offline Profile Quote Post Goto Top
 
Jory
Member Avatar
Member
[ *  *  *  *  *  * ]
I didn't understand how that stuff worked eigther.
But then I started to play around with it a bit, most of the time just doing that makes it easier to understand (for me anyway)
Offline Profile Quote Post Goto Top
 
shockwave-
My other title is a Ferrari
[ *  * ]
Basically, it posts a message a user types in a form, on a page. It's good for guestbooks. Really, it's a very simple forum, if you think abou it. I don't know PHP at all, just used a little HTML formatting, and got it posting how I wanted. ;)
Offline Profile Quote Post Goto Top
 
DDM
Member
[ *  * ]
Lord Shaun why dont you put that avatar of yours in your signature.....
Offline Profile Quote Post Goto Top
 
KodeCing
Member
[ * ]
A text file?
What the hell are you thinking?

It's all about the MySQL...
Offline Profile Quote Post Goto Top
 
Jory
Member Avatar
Member
[ *  *  *  *  *  * ]
Well, SQL servers are a bit harder to find, aren't they?
And for this, a txt will do just fine.
(And I'm pretty sure this code is faster to ;) )


But if you think he needs a script that uses SQL, why don't you make it.
(Ok, its not that hard it you know some SQL, but if you did, you'd also know its 'code' and not 'kode' <_< )
Offline Profile Quote Post Goto Top
 
shockwave-
My other title is a Ferrari
[ *  * ]
Well, I changed the script to write in an HTML file. Works fine. Just format a bit, and you're good.
Offline Profile Quote Post Goto Top
 
stevio27
That one guy
[ *  *  *  * ]
I've made a Guestbook in a much simpler way:

Make a forum called Guestbook, and post a topic in there. Then make the forum into a redirect link to the reply page for that topic. Then add a link for viewing the all-ready posted entries in the forum description.
Offline Profile Quote Post Goto Top
 
1 user reading this topic (1 Guest and 0 Anonymous)
« Previous Topic · Technology Chat · Next Topic »
Add Reply