Files

65 lines
1.6 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
session_start();
require '../includes/db.php';
if (!isset($_SESSION['admin'])) {
header('Location: connexion.php');
exit;
}
$id = $_GET['id'] ?? null;
if (!$id) {
header('Location: tabledebord.php');
exit;
}
// Récupère modifié//
$stmt = $pdo->prepare("SELECT * FROM articles WHERE id = ?");
$stmt->execute([$id]);
$article = $stmt->fetch(PDO::FETCH_ASSOC);
if (!$article) {
die("Article introuvable !");
}
$message = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$titre = trim($_POST['titre']);
$contenu = trim($_POST['contenu']);
if (!empty($titre) && !empty($contenu)) {
$update = $pdo->prepare("UPDATE articles SET titre = ?, contenu = ? WHERE id = ?");
$update->execute([$titre, $contenu, $id]);
$message = "Article modifié";
} else {
$message = "Tous les champs sont obligatoires.";
}
}
?>
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<title>Modifier un article</title>
</head>
<body>
<h2>Modifier larticle</h2>
<a href="tabledebord.php">← Retour</a>
<hr>
<form method="post">
<label>Titre :</label><br>
<input type="text" name="titre" value="<?= htmlspecialchars($article['titre']) ?>" required><br><br>
<label>Contenu :</label><br>
<textarea name="contenu" rows="6" cols="50" required><?= htmlspecialchars($article['contenu']) ?></textarea><br><br>
<button type="submit">Enregistrer les modifications</button>
</form>
<p style="color:green;"><?= $message ?></p>
</body>
</html>