-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadmin-post.php
52 lines (43 loc) · 1.24 KB
/
admin-post.php
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
<?php
if ($request->isMethod('POST')) {
if ($request->query->has('id')) {
$conn->update('posts', $request->request->all(), [
'id' => $request->query->getInt('id'),
]);
header('Location: ' . $request->server->get('SCRIPT_NAME') . '/admin/post?id=' . $request->query->get('id'));
exit;
} else {
$conn->insert('posts', $request->request->all());
header('Location: ' . $request->server->get('SCRIPT_NAME') . '/admin/post?id=' . $conn->lastInsertId());
exit;
}
}
$post = $conn->fetchAssoc("SELECT * FROM posts WHERE id = :id", array(
'id' => $request->query->getInt('id'), // (int) $_GET['id'],
));
?>
<script src="//cdn.ckeditor.com/4.4.7/full/ckeditor.js"></script>
<a href="<?= $request->server->get('SCRIPT_NAME') ?>/admin/post">
Cancel
</a>
<form action="" method="POST">
<div>
Heading: <br>
<input type="text" name="heading" value="<?= $post['heading'] ?>">
</div>
<div>
Intro: <br>
<textarea name="intro" id="" cols="30" rows="10"><?= $post['intro'] ?></textarea>
</div>
<div>
Content: <br>
<textarea name="content" id="" cols="30" rows="10"><?= $post['content'] ?></textarea>
</div>
<div>
<input type="submit" value="Save">
</div>
</form>
<script>
CKEDITOR.replace('intro');
CKEDITOR.replace('content');
</script>