10.3. Building the Comment Entry Form

You enable users to add new comments to your blog entries by providing them with a form to fill out.

This form needs to contain fields for the commenter's name, email address, and comment. Also, you need to store the blog entry's identifier to associate the comment with the blog.

To display this form, you create a new method called showCommentForm(), which accepts one argument, $blog_id, and outputs a form in HTML.

You can create this method by adding the code in bold to your Comments class in comments.inc.php:

<?php include_once 'db.inc.php'; class Comments { // Our database connection public $db; // Upon class instantiation, open a database connection public function __construct() { // Open a database ...

Get PHP for Absolute Beginners now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.