#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    2
    Rep Power
    0

    Comment FORM - comments.php


    Hi, I need the comments for my blog to work. They will be on the same page and automatically post. I searched the forum and tried a tutorial (can't post url link) , but still no bueno!

    here is the current html of the form:



    <div id="respond">

    <div class="cancel-comment-reply"><a rel="nofollow" id="cancel-comment-reply-link" href="#respond" style="display:none;">Cancel reply</a></div>
    <form action="comments.php" method="post" id="commentform">
    <h3 class="heading">LEAVE A REPLY</h3>
    <input type="text" name="comments" id="author" value="" tabindex="1" />
    <label for="author">Name <small>*</small></label><br/>

    <input type="text" name="email" id="email" value="" tabindex="2" />
    <label for="email">Email <small>*</small> <span>(not published)</span></label><br/>

    <input type="text" name="url" id="url" value="" tabindex="3" />
    <label for="url">Website</label>

    <textarea name="comment" id="comment" tabindex="4"></textarea>

    <p><input name="submit" type="submit" id="submit" tabindex="5" value="Post" /></p>

    <input type='hidden' name='comment_post_ID' value='' id='comment_post_ID' />
    <input type='hidden' name='comment_parent' id='comment_parent' value='0' />
    </form>
    </div>
    <div class="clearfix"></div>

    and here is the php i added as per the guys' instructions:

    <?php
    $hFile = fopen( "comments.txt", "a+" );
    fwrite( $hFile, "$comments" );
    fclose( $hFile );
    ?>


    I need the comments to post automatically on the page once the user presses send. Extreme novice! Sorry.


    I appreciate anyone's help on this. Thanks for your time.
  2. #2
  3. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,316
    Rep Power
    7171
    Writing a comment system is a simple but non-trivial feature. It's actually not a bad starting point at all for a new PHP programmer.

    However, the PHP code you have so far will not work. It looks like it's really outdated.

    There are you things you need to do: first you need to program a script to store the submitted comments somewhere, then you need to program a script to retrieve and display the stored comments.

    The most appropriate place to store the comments is in a database. An alternative is to store them in a file, like the code "the guy" gave you is trying to do. Storing the comments in a file is easier to understand for a beginner, but worse in pretty much every other way; particularly if you want to have additional fields like email.

    You should start by finding a basic tutorial on PHP. It will teach you the basic syntax of PHP and how to use $_POST and $_GET to retrieve submitted form values. Once you understand the basics, you can find a tutorial on SQL for MySQL and on PHP+MySQL which will teach you how to use a database.
    PHP FAQ

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    2
    Rep Power
    0
    thank you!

IMN logo majestic logo threadwatch logo seochat tools logo