-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate.php
More file actions
48 lines (45 loc) · 2.05 KB
/
create.php
File metadata and controls
48 lines (45 loc) · 2.05 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
<?php
require_once __DIR__ . '/partials/header.php';
if (!isset($_SESSION['user_id'])) { header('Location: /miniblog/login.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("INSERT INTO posts (user_id, title, content) VALUES (?,?,?)")
->execute([$_SESSION['user_id'], $title, $content]);
$_SESSION['flash']['success'] = 'Post created 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>Create Post</h2>
<a href="/miniblog/dashboard.php" class="btn btn-outline-secondary">
<i class="bi bi-arrow-left"></i> Back
</a>
</div>
<form method="post">
<div class="mb-3">
<label class="form-label">Title</label>
<input type="text" name="title" class="form-control" placeholder="Enter post title..." required>
<div class="form-text">Make it catchy and descriptive</div>
</div>
<div class="mb-3">
<label class="form-label">Content</label>
<textarea name="content" class="form-control" rows="8" placeholder="Write your post content here..." required></textarea>
<div class="form-text">Markdown is supported</div>
</div>
<div class="d-flex justify-content-end gap-2">
<button type="reset" class="btn btn-outline-secondary">Reset</button>
<button type="submit" class="btn btn-primary">
<i class="bi bi-send"></i> Publish
</button>
</div>
</form>
</div>
</div>
<?php require_once __DIR__ . '/partials/footer.php'; ?>