Hi! Ok, so if any of you (*cough* Angelwatt *cough*) have been following my previous posts, you'll know that I'm creating my first blog. Right now, I'm at the point of adding the comments. I've looked at numerous tutorials and have managed to scrape up a code. Of course, it doesn't work, but that's why I'm here. WHat happens is, when you submit the comment, it redirects you to "comments_process.php" instead of displaying the comment. So here we go:
The form:
comment_process.php:
comment_display.php:
This site is temporarily live for testing purposes: http://imasterweb.net/blog_post.php
Please be gentle as I am an EXTREME beginner. Thanks a ton!!!!
-iMaster
The form:
Code:
<div id="comments_wrap">
<form method="post" action="comment_process.php">
<input type="hidden" name="entry" value="blog_post.html" />
<label for="name">Name</label>
<input type="text" name="name" value="" />
<label for="website">Website</label>
<input type="text" name="website" value="" />
<label for="comment">Comment</label>
<textarea rows="15" cols="5" name="comment"></textarea>
<input type="submit" name="submit" value="Submit" id="submit" />
</form>
<?php include("comment_display.php"); ?>
</div>
comment_process.php:
Code:
<?php
if (isset($_POST['submit'])) {
if (empty($_POST['name']) || empty($_POST['comment'])) {
die("You have forgotten to fill in one of the required fields! Please make sure you submit a name and comment.");
}
$entry = htmlspecialchars(strip_tags($_POST['entry']));
$name = htmlspecialchars(strip_tags($_POST['name']));
$webste = htmlspecialchars(strip_tags($_POST['website']));
$comment = htmlspecialchars(strip_tags($_POST['comment']));
$comment = nl2br($comment);
if (!get_magic_quotes_gpc()) {
$name = addslashes($name);
$website = addslashes($website);
$comment = addslashes($comment);
}
mysql_connect ('localhost', '*********', '*********') ;
mysql_select_db ('*********');
$result = mysql_query("INSERT INTO php_blog_comments (entry, name, website, comment, timestamp) VALUES ('$entry','$name','$website','$comment','$timestamp')");
}
?>
comment_display.php:
Code:
<?php
mysql_connect ('localhost', '******', '******') ;
mysql_select_db ('******');
$query = mysql_query("SELECT * FROM `php_blog_comments` WHERE entry='$entry'");
while($row = mysql_fetch_assoc($query)) {
echo '
<div id="comment_'.$row['id'].';">
<strong>'.$row['name'].'</strong> Says,
'$row['comment'].'
</div>';
}
?>
This site is temporarily live for testing purposes: http://imasterweb.net/blog_post.php
Please be gentle as I am an EXTREME beginner. Thanks a ton!!!!
-iMaster