public static function insertPost() { global $bdd; $title = $_POST['title']; $body = $_POST['body']; $getPicture = User::checkFile(); $picture = !is_array($getPicture) ? null : User::moveFile($getPicture, 'post'); $date = date_format(date_create(), 'Y-m-d H:i:s'); $user = User::getUser(); try { $insert = $bdd->prepare("\n\t\t\t\tINSERT INTO `posts` (`title`, `body`, `user_id`, `image_id`, `created_at`) \n\t\t\t\tVALUES \t\t\t\t(:title, :body, :user_id, :image_id, :created_at)\n\t\t\t"); $insert->bindParam(':title', $title, \PDO::PARAM_STR); $insert->bindParam(':body', $body, \PDO::PARAM_STR); $insert->bindParam(':user_id', $user['id'], \PDO::PARAM_INT); $insert->bindParam(':image_id', $picture, \PDO::PARAM_INT); $insert->bindParam(':created_at', $date, \PDO::PARAM_STR); $insert->execute(); echo '<a href="post.php?id=' . $bdd->lastInsertId() . '">Go see your post</a>'; } catch (Exception $e) { die("Some error occured while the register process : " . $e); } }