Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6

Thread: Comments

  1. #1
    New to the CF scene
    Join Date
    Apr 2006
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Comments

    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?

  • #2
    New Coder
    Join Date
    Apr 2006
    Location
    UK
    Posts
    50
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You could do it with mySQL, saving the comment and the persons name, as well as perhaps an id and a timestamp.

  • #3
    New Coder
    Join Date
    Mar 2006
    Location
    Denver, CO
    Posts
    43
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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?

  • #4
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    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.

    PHP Code:
    $outputFile fopen($appropriateTextFile"a"); 

  • #5
    Senior Coder
    Join Date
    Nov 2002
    Location
    North-East, UK
    Posts
    1,265
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #6
    New Coder
    Join Date
    Mar 2006
    Location
    Denver, CO
    Posts
    43
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •