= 1 ORDER BY ID DESC LIMIT 1"; $request = $pdo->prepare($sqlRequest); $request->execute(); $result = $request->fetchAll(PDO::FETCH_ASSOC); $articleID = (int)$result[0]['ID'] + 1; file_put_contents($rootFilePath . "content/articles/" . $articleID . ".md", nl2br($_POST['article-content'])); $sqlRequest = "INSERT INTO articles (ID, title, author, resume, classification) VALUES (:articleID, :title, :author, :resume, :classification)"; $request = $pdo->prepare($sqlRequest); $request->bindParam(":articleID", $articleID); $request->bindParam(":title", htmlspecialchars($_POST['article-title'])); $request->bindParam(":author", $_SESSION['userID']); $request->bindParam(":resume", htmlspecialchars($_POST['article-resume'])); $request->bindParam(":classification", $_POST['classification'], PDO::PARAM_INT); if($request->execute()) { $webhook = "https://discord.com/api/webhooks/1267506225692545024/lbQ2utQVHiE_QxdhmmKzHc9XGnekqc_6G6CF478VER3hDjzDuNvTcGeKw1P-AZ8vLfai"; $message = "Nouvel Article : https://e59.fr/news?article=" . $articleID; $data = [ 'username' => "e59.fr", 'content' => $message, ]; $ch = curl_init($webhook); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Content-Type: application/json' ]); $response = curl_exec($ch); if ($response === false) { throw new Exception('Erreur CURL : ' . curl_error($ch)); } $httpStatusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); header("Location: /news?article=" . $articleID); } else { $status = "Erreur SQL"; } } ?>