BLOG DESIGN (Best web hosting site) SOLUTIONS The subject, body, and headers
BLOG DESIGN SOLUTIONS The subject, body, and headers are constructed using the following code: $emailsubject = “Comment added to: “.$posttitle; $emailbody = “Comment on ‘”.$posttitle.”‘”.”\r\n” .”http://www.your-domain-name.com/post.php?post_id=”.$post_id .”#c”.$comment_id.”\r\n\r\n” .$comment.”\r\n\r\n” .$name.” (”.$website.”)\r\n\r\n”; $emailbody = stripslashes($emailbody); $emailheader = “From: “.$name.” <".$email.">\r\n”.”Reply-To: “.$email; @mail(”you@your-domain-name.com”, $emailsubject, $emailbody, $emailheader); Remember to replace www.your-domain-name.com with your website domain, and you@your-domain-name.com with your e-mail address. Note also the @ in front of the mail function. This prevents any errors being written to the screen if for some reason the mail function fails. And the final line of the comment insert script is as follows: header(”Location: post.php?post_id=$post_id&message=$message”); The header function creates an HTTP header, which is essentially an instruction to the web server. In this case, the instruction is to go to the post page with a success message appended to the query string. This step prevents readers from submitting their comment twice if they click reload in their browser. So now readers can add comments to your posts, and you are notified each time that happens. The final step is to show those comments in your blog. Let s look at the script that will pull the comments from the database. Add this script to the end of PHP code at the top of post.php: if ($myposts) { $sql = “SELECT comment_id, name, website, comment FROM comments . WHERE post_id = $post_id”; $result3 = mysql_query($sql); $mycomments = mysql_fetch_array($result3); } If the post exists, the comments for this post are pulled from the database. Next you can display them on the page by inserting this code into the posts div, just after the closing ?> delimiter in your post loop:
Comments
This entry was posted on Monday, January 14th, 2008 at 6:01 pm and is filed under Apache. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.