Supprimer article-index-css/modifier.php
This commit is contained in:
@@ -1,64 +0,0 @@
|
|||||||
<?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 l’article</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>
|
|
||||||
Reference in New Issue
Block a user