48 lines
1.4 KiB
PHP
48 lines
1.4 KiB
PHP
<?php
|
|
require '../include/db.php';
|
|
require '../include/auth.php';
|
|
requireLogin();
|
|
|
|
$errors = [];
|
|
$titre = '';
|
|
$contenu = '';
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$titre = trim($_POST['titre'] ?? '');
|
|
$contenu = trim($_POST['contenu'] ?? '');
|
|
|
|
if ($titre === '' || $contenu === '') {
|
|
$errors[] = 'Tous les champs sont obligatoires.';
|
|
} else {
|
|
$stmt = $pdo->prepare('INSERT INTO articles (titre, contenu, date_creation) VALUES (:titre, :contenu, :date)');
|
|
$stmt->execute([
|
|
':titre' => $titre,
|
|
':contenu' => $contenu,
|
|
':date' => date('Y-m-d H:i:s'),
|
|
]);
|
|
header('Location:board.php');
|
|
exit;
|
|
}
|
|
}
|
|
?>
|
|
|
|
<!doctype html>
|
|
<html lang="fr">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<title>Ajouter un article</title>
|
|
<link rel="stylesheet" href="/assets/style.css">
|
|
</head>
|
|
<body>
|
|
<h1>Ajouter un article</h1>
|
|
<?php foreach ($errors as $e): ?>
|
|
<p class="error"><?= htmlspecialchars($e) ?></p>
|
|
<?php endforeach; ?>
|
|
<form method="post">
|
|
<label>Titre<br><input type="text" name="titre" value="<?= htmlspecialchars($titre) ?>" required></label><br>
|
|
<label>Contenu<br><textarea name="contenu" rows="10" required><?= htmlspecialchars($contenu) ?></textarea></label><br>
|
|
<button type="submit">Publier</button>
|
|
<a href="board.php">Annuler</a>
|
|
</form>
|
|
</body>
|
|
</html>
|