February 1st, 2013, 02:28 PM
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 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" />
<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' />
and here is the php i added as per the guys' instructions:
$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.
February 2nd, 2013, 11:20 AM
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.
February 4th, 2013, 11:29 AM