echo json_encode($data); } } } else { if ($mode == 'createTopic') { $data = array("mode" => $mode, "success" => 0, "error" => 0); //Let's extract all the data that we need in order to create a topic $user_name = $_POST['name']; //Here we'll check whether the user exists in the database or not $user = $database->getUserDetails($user_name); //Success if ($user != false) { $uid = $user; $subject = $_POST['topicSubject']; $content = $_POST['topicContent']; $result = $database->createTopic($subject, $uid, $content); if ($result != false) { $data["success"] = 1; $data["error"] = 0; $data["user"]["uid"] = $uid; $data["topic"]["subject"] = $subject; $data["topic"]["created_by"] = $uid; $data["topic"]["content"] = $content; echo json_encode($data); } else { $data["success"] = 0; $data["error"] = 1; $data["error_message"] = "Something went wrong while creating a new topic!"; $data["user"]["uid"] = $uid; echo json_encode($data); }