Initial commit : CMS Simplifié
This commit is contained in:
55
public/add.php
Normal file
55
public/add.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
session_start();
|
||||
if(!isset($_SESSION['user_id'])){ header('Location: login.php'); exit; }
|
||||
require __DIR__ . '/../inc/db.php';
|
||||
$error = null;
|
||||
if($_SERVER['REQUEST_METHOD']==='POST'){
|
||||
$titre = trim($_POST['titre'] ?? '');
|
||||
$contenu = trim($_POST['contenu'] ?? '');
|
||||
if($titre!=='' && $contenu!==''){
|
||||
$stmt = $pdo->prepare("INSERT INTO articles(titre,contenu) VALUES(?,?)");
|
||||
$stmt->execute([$titre,$contenu]);
|
||||
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>Ajouter 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">Ajouter un 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>
|
||||
</div>
|
||||
<div>
|
||||
<label class="form-label">Contenu</label>
|
||||
<textarea class="form-control" rows="10" name="contenu" required></textarea>
|
||||
</div>
|
||||
<div class="d-flex gap-2">
|
||||
<button class="btn btn-accent">Enregistrer</button>
|
||||
<a class="btn btn-outline-accent" href="admin.php">Annuler</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user