56 lines
1.9 KiB
PHP
56 lines
1.9 KiB
PHP
<?php
|
|
require_once '../db/config.php';
|
|
|
|
$id = $_GET['id'] ?? null;
|
|
$page = [];
|
|
$title = 'Create Page';
|
|
|
|
if ($id) {
|
|
$stmt = db()->prepare('SELECT * FROM pages WHERE id = ?');
|
|
$stmt->execute([$id]);
|
|
$page = $stmt->fetch();
|
|
$title = 'Edit Page';
|
|
}
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$slug = $_POST['slug'];
|
|
$page_title = $_POST['title'];
|
|
$content = $_POST['content'];
|
|
|
|
if ($id) {
|
|
$stmt = db()->prepare('UPDATE pages SET slug = ?, title = ?, content = ? WHERE id = ?');
|
|
$stmt->execute([$slug, $page_title, $content, $id]);
|
|
} else {
|
|
$stmt = db()->prepare('INSERT INTO pages (slug, title, content) VALUES (?, ?, ?)');
|
|
$stmt->execute([$slug, $page_title, $content]);
|
|
}
|
|
|
|
header('Location: pages.php');
|
|
exit;
|
|
}
|
|
|
|
include 'header.php';
|
|
?>
|
|
|
|
<h1><?php echo $title; ?></h1>
|
|
|
|
<form method="POST">
|
|
<div class="mb-3">
|
|
<label for="title" class="form-label">Title</label>
|
|
<input type="text" class="form-control" id="title" name="title" value="<?php echo htmlspecialchars($page['title'] ?? ''); ?>" required>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="slug" class="form-label">Slug</label>
|
|
<input type="text" class="form-control" id="slug" name="slug" value="<?php echo htmlspecialchars($page['slug'] ?? ''); ?>" required>
|
|
<div class="form-text">The slug is the URL-friendly version of the name. It is usually all lowercase and contains only letters, numbers, and hyphens.</div>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="content" class="form-label">Content</label>
|
|
<textarea class="form-control" id="content" name="content" rows="10" required><?php echo htmlspecialchars($page['content'] ?? ''); ?></textarea>
|
|
</div>
|
|
<button type="submit" class="btn btn-primary">Save</button>
|
|
<a href="pages.php" class="btn btn-secondary">Cancel</a>
|
|
</form>
|
|
|
|
<?php include 'footer.php'; ?>
|