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 - building the Blog Post Creator

Although it sounds fancy, Blog Post Creator is just a webpage that shows a form where the user can type in the text of his/her article, and then save it by submitting the form:

  1. Open up your text editor. Put the following code in a new file:
    <?php $action = (!empty($_POST['btn_submit']) && ($_POST['btn_submit'] === 'Save')) ? 'save_article' : 'show_form'; switch($action){ case 'save_article': try { $connection = new Mongo(); $database = $connection->selectDB('myblogsite'); $collection = $database-> selectCollection('articles'); $article = array{ 'title' => $_POST['title'], 'content' => $_POST['content'], 'saved_at' => new MongoDate() }; $collection->insert($article); } catch(MongoConnectionException ...

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