61 lines
2.4 KiB
PHP
61 lines
2.4 KiB
PHP
<?php
|
||
session_start();
|
||
if(!isset($_SESSION['user_id'])){ header('Location: login.php'); exit; }
|
||
require __DIR__ . '/../inc/db.php';
|
||
$id = filter_input(INPUT_GET,'id',FILTER_VALIDATE_INT);
|
||
if(!$id){ http_response_code(404); exit('404'); }
|
||
$stmt = $pdo->prepare("SELECT id,titre,contenu FROM articles WHERE id=?");
|
||
$stmt->execute([$id]);
|
||
$article = $stmt->fetch();
|
||
if(!$article){ http_response_code(404); exit('404'); }
|
||
$error = null;
|
||
if($_SERVER['REQUEST_METHOD']==='POST'){
|
||
$titre = trim($_POST['titre'] ?? '');
|
||
$contenu = trim($_POST['contenu'] ?? '');
|
||
if($titre!=='' && $contenu!==''){
|
||
$upd = $pdo->prepare("UPDATE articles SET titre=?,contenu=? WHERE id=?");
|
||
$upd->execute([$titre,$contenu,$id]);
|
||
header('Location: admin.php'); exit;
|
||
} else { $error = 'Champs obligatoires.'; }
|
||
}
|
||
?>
|
||
<!doctype html>
|
||
<html lang="fr">
|
||
<head>
|
||
<meta charset="utf-8">
|
||
<meta name="viewport" content="width=device-width,initial-scale=1">
|
||
<title>Modifier un article</title>
|
||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
||
<link href="assets/style.css?v=6" rel="stylesheet">
|
||
</head>
|
||
<body>
|
||
<nav class="navbar">
|
||
<div class="container container-narrow d-flex align-items-center gap-3">
|
||
<a class="navbar-brand fw-semibold" href="admin.php">Administration</a>
|
||
<div class="ms-auto navbar-text">Connecté: <?= htmlspecialchars($_SESSION['user_login']) ?></div>
|
||
<a class="btn btn-outline-accent btn-sm" href="logout.php">Se déconnecter</a>
|
||
</div>
|
||
</nav>
|
||
|
||
<main class="container container-narrow py-4" style="max-width:820px">
|
||
<div class="card p-4">
|
||
<h1 class="h4 mb-3">Modifier l’article</h1>
|
||
<?php if($error): ?><div class="alert alert-danger"><?= htmlspecialchars($error) ?></div><?php endif; ?>
|
||
<form method="post" class="vstack gap-3">
|
||
<div>
|
||
<label class="form-label">Titre</label>
|
||
<input class="form-control" type="text" name="titre" required value="<?= htmlspecialchars($article['titre']) ?>">
|
||
</div>
|
||
<div>
|
||
<label class="form-label">Contenu</label>
|
||
<textarea class="form-control" rows="10" name="contenu" required><?= htmlspecialchars($article['contenu']) ?></textarea>
|
||
</div>
|
||
<div class="d-flex gap-2">
|
||
<button class="btn btn-accent">Mettre à jour</button>
|
||
<a class="btn btn-outline-accent" href="admin.php">Annuler</a>
|
||
</div>
|
||
</form>
|
||
</div>
|
||
</main>
|
||
</body>
|
||
</html>
|