-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathedit.php
More file actions
63 lines (55 loc) · 2.6 KB
/
edit.php
File metadata and controls
63 lines (55 loc) · 2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
require_once __DIR__ . '/partials/header.php';
if (!isset($_SESSION['user_id'])) { header('Location: /miniblog/login.php'); exit; }
$id = (int)($_GET['id'] ?? 0);
$stmt = $pdo->prepare("SELECT * FROM posts WHERE id = ? AND user_id = ?");
$stmt->execute([$id, $_SESSION['user_id']]);
$post = $stmt->fetch();
if (!$post) { header('Location: /miniblog/dashboard.php'); exit; }
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$title = trim($_POST['title']);
$content = trim($_POST['content']);
if ($title === '' || $content === '') {
$_SESSION['flash']['danger'] = 'Title and content required.';
} else {
$pdo->prepare("UPDATE posts SET title = ?, content = ? WHERE id = ?")
->execute([$title, $content, $id]);
$_SESSION['flash']['success'] = 'Post updated successfully!';
header('Location: /miniblog/dashboard.php'); exit;
}
}
?>
<div class="card shadow-sm">
<div class="card-body">
<div class="d-flex justify-content-between align-items-center mb-4">
<h2 class="fw-bold mb-0">Edit Post</h2>
<a href="/dashboard.php" class="btn btn-outline-secondary">
<i class="bi bi-arrow-left"></i> Back to Dashboard
</a>
</div>
<form method="post">
<div class="mb-4">
<label for="title" class="form-label fw-bold">Post Title</label>
<input type="text" name="title" id="title" class="form-control form-control-lg"
value="<?= htmlspecialchars($post['title']) ?>" required>
<div class="form-text">Make it catchy and descriptive</div>
</div>
<div class="mb-4">
<label for="content" class="form-label fw-bold">Content</label>
<textarea name="content" id="content" class="form-control" rows="12" required><?=
htmlspecialchars($post['content'])
?></textarea>
<div class="form-text">Markdown is supported</div>
</div>
<div class="d-grid gap-2 d-md-flex justify-content-md-end">
<a href="/miniblog/post.php?id=<?= $post['id'] ?>" class="btn btn-outline-primary me-md-2">
<i class="bi bi-eye"></i> View Post
</a>
<button type="submit" class="btn btn-primary">
<i class="bi bi-save"></i> Save Changes
</button>
</div>
</form>
</div>
</div>
<?php require_once __DIR__ . '/partials/footer.php'; ?>