Results 1 to 23 of 23

Thread: [RESOLVED] PHP Comment Box

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2007
    Location
     
    Posts
    453

    Resolved [RESOLVED] PHP Comment Box

    Alright, I really need help with this, I have no idea about php, I used to be ok with it, but now I cant really remember anything. I need to make a commentbox on one of my sites, but all I want it to do is submit it to a text file in this format:
    Code:
    Name:
    Comment:
    ----------------
    I don't remember how to do this, but this shouldn't require me to setup a database because it is being added to a text file, right?
    Thanks in advance.
    Haikus are easy.
    But sometimes they don't make sense.
    Refrigerator.

  2. #2
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: PHP Comment Box

    Right.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2007
    Location
     
    Posts
    453

    Re: PHP Comment Box

    Right?
    Haikus are easy.
    But sometimes they don't make sense.
    Refrigerator.

  4. #4
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: PHP Comment Box

    he answered the question that you asked. Do you have any other questions?
    My usual boring signature: Something

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2007
    Location
     
    Posts
    453

    Re: PHP Comment Box

    no, but how would I do that, that was my question...
    Haikus are easy.
    But sometimes they don't make sense.
    Refrigerator.

  6. #6
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: PHP Comment Box

    Quote Originally Posted by Bobalandi
    but this shouldn't require me to setup a database because it is being added to a text file, right?
    That is the only sentence with a question mark at the end, so it is the only question you asked.

    A more appropriate question would be "How would i do this".

    well you need a form...

    HTML Code:
    <form action="YOUR PAGE.php" method="POST">
    <input type="text" name="name">
    <textarea name="comment"></textarea>
    <input type="submit" name="submit">
    and your code...

    PHP Code:
    if (isset($_POST['name'])&&isset($_POST['comment'])) {
        
    $myFile "comments.txt";

        
    $fh fopen($myFile'w') or die("can't open file");

        
    $stringData "Name: " $_POST['name'] . "\n";
        
    fwrite($fh$stringData);

        
    $stringData "Comment: " $_POST['comment'] . "\n";
        
    fwrite($fh$stringData);

        
    $stringData "-----------------------------------\n\n\n";
        
    fwrite($fh$stringData);

        
    fclose($fh);

    php.net is a great tool
    My usual boring signature: Something

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2007
    Location
    &nbsp;
    Posts
    453

    Re: PHP Comment Box

    php.net? but thanks for the code...
    Haikus are easy.
    But sometimes they don't make sense.
    Refrigerator.

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2007
    Location
    &nbsp;
    Posts
    453

    Re: PHP Comment Box

    hmmm... It didnt work...
    Haikus are easy.
    But sometimes they don't make sense.
    Refrigerator.

  9. #9
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: PHP Comment Box

    Quote Originally Posted by Bobalandi
    hmmm... It didnt work...
    That's about as helpful as mixing marmalade with Toilet Duck.
    What happens to make it appear to not work?

  10. #10
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: PHP Comment Box

    Quote Originally Posted by Bobalandi
    php.net? but thanks for the code...
    php.net is the PHP home page... all the built in functions of php, with examples. google is also a great tool.

    Google: "php append to file", get the results you want
    My usual boring signature: Something

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2007
    Location
    &nbsp;
    Posts
    453

    Re: PHP Comment Box

    oo, the website, I thought you meant an app, thanks. And as for it not working, it just doesnt accomplish anything, all it does is forward you to the php page, not add the text or anything.
    Haikus are easy.
    But sometimes they don't make sense.
    Refrigerator.

  12. #12
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: PHP Comment Box

    post all the code you have on the page
    My usual boring signature: Something

  13. #13

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2007
    Location
    &nbsp;
    Posts
    453

    Re: PHP Comment Box

    ok, I have 3 pages one is an empty text page called comments.txt
    next it the html form on one page.
    Code:
    <form action="comment.php" method="POST" id="Comment">
        	<label>Name:</label><br /> 
        	<input type="text" name="name"><br />
            <label>Comment:</label><br />
        	<textarea name="comment"></textarea><br />
        	<input type="submit" name="submit">
        </form>
    last ly there is the php page, comment.php
    Code:
    if (isset($_POST['name'])&&isset($_POST['comment'])) {
        $myFile = "comments.txt";
    
        $fh = fopen($myFile, 'w') or die("can't open file");
    
        $stringData = "Name: " . $_POST['name'] . "\n";
        fwrite($fh, $stringData);
    
        $stringData = "Comment: " . $_POST['comment'] . "\n";
        fwrite($fh, $stringData);
    
        $stringData = "-----------------------------------\n\n\n";
        fwrite($fh, $stringData);
    
        fclose($fh);
    }
    Haikus are easy.
    But sometimes they don't make sense.
    Refrigerator.

  14. #14
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: PHP Comment Box

    do you have php tags? <?php & ?>
    My usual boring signature: Something

  15. #15

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2007
    Location
    &nbsp;
    Posts
    453

    Re: PHP Comment Box

    umm... should I? that is everything that is on the page? and also, how can I maek it redirect somewhere?
    Haikus are easy.
    But sometimes they don't make sense.
    Refrigerator.

  16. #16
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: PHP Comment Box

    haha. yes, php tags are required. it will be just outputted as html if you dont.

    redirect: header("Location: mypage.php");
    My usual boring signature: Something

  17. #17

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2007
    Location
    &nbsp;
    Posts
    453

    Re: PHP Comment Box

    ok, thanks I appreciate everything, resolved, I think.
    Haikus are easy.
    But sometimes they don't make sense.
    Refrigerator.

  18. #18
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: [RESOLVED] PHP Comment Box

    no problems! dont forget to give rep accordingly.
    My usual boring signature: Something

  19. #19

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2007
    Location
    &nbsp;
    Posts
    453

    Re: [RESOLVED] PHP Comment Box

    It still isn't working for some reason, but that is ok, I decided to work with asp.net instead.
    Haikus are easy.
    But sometimes they don't make sense.
    Refrigerator.

  20. #20
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: [RESOLVED] PHP Comment Box

    gasp! how could you move to asp.net! nooo!!!
    lol

    ok, well as long as you find a programming language that you can work with, then that is always the best.

    Thanks for the rep
    My usual boring signature: Something

  21. #21

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2007
    Location
    &nbsp;
    Posts
    453

    Re: [RESOLVED] PHP Comment Box

    you deserved it (the rep lol), and I found asp.net to better cater to my needs, and I have a bunch of people, who I know who can help me with, and then there is timeshifter... lol
    Haikus are easy.
    But sometimes they don't make sense.
    Refrigerator.

  22. #22
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: [RESOLVED] PHP Comment Box

    lol. well i wish you the best on your ASP.NET journey
    My usual boring signature: Something

  23. #23

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2007
    Location
    &nbsp;
    Posts
    453

    Re: [RESOLVED] PHP Comment Box

    Thanks
    Haikus are easy.
    But sometimes they don't make sense.
    Refrigerator.

Posting Permissions

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



Click Here to Expand Forum to Full Width