Refonte complète du projet
This commit is contained in:
50
public/edit.php
Normal file
50
public/edit.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
session_start();
|
||||
require_once '../includes/db.php';
|
||||
require_once '../includes/header.php';
|
||||
|
||||
if (!isset($_SESSION['user'])) {
|
||||
header("Location: login.php");
|
||||
exit;
|
||||
}
|
||||
|
||||
$id = $_GET['id'] ?? null;
|
||||
if (!$id || !is_numeric($id)) {
|
||||
echo "<p>Article introuvable (404)</p>";
|
||||
require_once '../includes/footer.php';
|
||||
exit;
|
||||
}
|
||||
|
||||
$stmt = $pdo->prepare("SELECT * FROM articles WHERE id = ?");
|
||||
$stmt->execute([$id]);
|
||||
$article = $stmt->fetch();
|
||||
|
||||
if (!$article) {
|
||||
echo "<p>Article introuvable (404)</p>";
|
||||
require_once '../includes/footer.php';
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$titre = $_POST['titre'] ?? '';
|
||||
$contenu = $_POST['contenu'] ?? '';
|
||||
if ($titre && $contenu) {
|
||||
$stmt = $pdo->prepare("UPDATE articles SET titre=?, contenu=? WHERE id=?");
|
||||
$stmt->execute([$titre, $contenu, $id]);
|
||||
echo "<p>Article mis à jour avec succès.</p>";
|
||||
} else {
|
||||
echo "<p style='color:red;'>Veuillez remplir tous les champs.</p>";
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
<h2>Modifier l'article</h2>
|
||||
<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="5" required><?= htmlspecialchars($article['contenu']) ?></textarea><br><br>
|
||||
<input type="submit" value="Modifier">
|
||||
</form>
|
||||
|
||||
<?php require_once '../includes/footer.php'; ?>
|
||||
Reference in New Issue
Block a user