O'Reilly logo

PHP and MongoDB Web Development by Rubayeet Islam

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action - posting comments to blog posts

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required