public function savePost($data_post) { $data = new BlogPostModel($data_post); $data->setId($data_post['id']); $data->setTitle($data_post['title']); $data->setBody($data_post['body']); if ($data->getId() == null) { //SQL insert $sql = "INSERT INTO posts(title, body, created) " . "VALUES ('{$data->getTitle()}', '{$data->getBody()}','" . date('Y-m-d H:i:s') . "');"; mysqli_query($this->con, $sql); } else { $sql = "UPDATE posts SET title = '{$data->getTitle()}', body = '{$data->getBody()}', created = '" . date('Y-m-d H:i:s') . "' " . "WHERE id = {$data->getId()} "; mysqli_query($this->con, $sql); } $posts = $this->get_post($data->getId()); if (!empty($posts)) { return $posts[0]; } }