Comment form, which posts comments on the website

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Nylen
Forum Newbie
Posts: 2
Joined: Thu Nov 09, 2006 6:50 pm

Comment form, which posts comments on the website

Post by Nylen »

I'm trying to create a form with which people can post their comments on my website.
What I tried to do was create the layout in html 'post' the information to a PHP file, write the data to the end of a txt file (each info in new line), and then make the script read the file and print it.
Is this supposed to work?
If not then what are the alternatives?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

It could work, yea..

I would preferably use a database to store the comments.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Post by califdon »

I agree with Jcart, if this is a real application. I would go further and say that there are many cool scripts you can download for good looking 'guest book' functions, which this sounds like.

If you are trying to learn PHP and using this as an exercise, then Good For You! That's a great way to learn. If you haven't yet gotten around to learning database handling, then do it as you proposed. Otherwise, a database solution offers many advantages, including: ease of maintenance (such as deleting unwanted entries), ability to search or even display in different sequence, etc.
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

Sometimes databases aren't available. If that's the case, check out serialize() which prevents a lot of pitfalls in text files. If you get a lot of data this method won't scale, though.
Nylen
Forum Newbie
Posts: 2
Joined: Thu Nov 09, 2006 6:50 pm

Post by Nylen »

Thank you for the help, I'll keep doing it this way then. I am learning PHP now, and my website is a good excuse for that. (I already know C and C++, so basically it's just the high number of external functions that gets me confused occasionally.)
Post Reply