<?php //$m = new MongoClient("mongodb://*****:*****@ds063870.mongolab.com:63870/notex_mini"); $m = new MongoDB\Driver\Manager("127.0.0.1"); // $db = $m->notex_mini; // select a database $db = $m->selectDB("NoteX_mini"); $subject = $_POST['title']; $problem = $_POST['topic']; $solution = $_POST['text']; $link1 = $_POST['linkText']; // select a collection $db->createCollection($subject); $solution = " " . str_replace("\\\"", "\"", $solution); $solution = str_replace("-", ":", $solution); if (isset($_POST['code'])) { $solution = "<pre><code>" . $solution . "</code></pre>"; } $subject = strtolower($subject); $collection = $db->{$subject}; if ($subject == "dictionary") { $document = array("problem" => $problem, "solution" => $solution); } else { $document = array("problem" => $problem, "solution" => $solution, "link" => $link1); } // add a record //echo $document; $find1 = array("problem" => $problem); $cursor = $collection->find($find1); $cnt = $cursor->count(); if ($cnt != 0) { foreach ($cursor as $document) {