We are going to modify blog.php
so that readers can post comments on an article. The reader will enter his name, e-mail address, and the comment in a form right below the article. We are also going to create a new PHP script, comment.php
, that receives the user-submitted comment, saves it in the database, and redirects to the original blog post where the user can see his own submitted comment:
1. Open
blog.php
in your text editor and replace the existing code in it with the following:<?php $id = $_GET['id']; try { $connection = new Mongo(); $database = $connection->selectDB('myblogsite'); $collection = $database->selectCollection('articles'); } catch(MongoConnectionException $e) { die("Failed to connect to database ".$e->getMessage()); } $article = $collection->findOne(array('_id' => new MongoId($id))); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional...