...

View Full Version : Comments



M24KPM
04-30-2006, 10:52 PM
Ok here is what I would like to do...

Have a form on a page that allows a person to enter a name, and a comment. Then what they post will show up at the bottom of the page...any ideas?

cdwhalley.com
05-01-2006, 11:14 AM
You could do it with mySQL, saving the comment and the persons name, as well as perhaps an id and a timestamp.

JeremyH
05-01-2006, 07:46 PM
I'd like to ask antother comments question...

I have a form where the user chooses the topic that he/she wants to comment on with a pulldown menu. like this....

1. apples
2. oranges
3. mangos

If the user types in a comment about oranges, it will be written to a text file called 2.txt. Instead of having premade empty text files for each topic, can I use PHP to see if there is the appropriate txt file in the directory and write to it, and if it doesn't exist, can it generate an empty txt file with the appropriate name (1.txt, 2.txt, 3.txt)?

A book I'm reading hints at this but doesn't explain. Any ideas?

Fumigator
05-02-2006, 03:43 PM
can I use PHP to see if there is the appropriate txt file in the directory and write to it, and if it doesn't exist, can it generate an empty txt file with the appropriate name (1.txt, 2.txt, 3.txt)?

Yep! If you open a text file in mode "a" (append), it will place the pointer at the end of the file in write mode; if the file doesn't exist, it will create it.


$outputFile = fopen($appropriateTextFile, "a");

degsy
05-02-2006, 03:51 PM
Here is a basic grafitti script
http://degs.co.uk/test/hct/file_graffiti.php

Personally I would go the database method. It will make things alot simpler and tidier in the future.

JeremyH
05-02-2006, 04:32 PM
The database sounds like a good way to go. I'll have to read up on that though. I'm new to PHP but I can see the possibilities there.

Fumigator, would your solution only add to a preexisting file? I want to know if there is a script or function in PHP that would say "generate a file called whatever.txt and place the comments in it." Doesn't the appending mode only add to an already existing file?

Thanks for your suggestions!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum