forked from engrraza/blog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd_post.php
110 lines (71 loc) · 1.87 KB
/
add_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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<?php
include_once('resources/init.php');
if (isset($_POST['title'], $_POST['contents'], $_POST['category'])) {
$errors = array();
$title = trim($_POST['title']);
$contents = trim($_POST['contents']);
if (empty($title)) {
$errors[] = 'You must submit some title';
}
if (empty($contents)) {
$errors[] = 'You must enter some text here';
}
if (! category_exists('id', $_POST['category'])) {
$errors[] = "That category does not exist";
}
if (strlen($title) > 255) {
$errors[] = "The title cannot be longer than 255 characters ";
}
if (empty($errors) ) {
add_post($title, $contents, $_POST['category']);
$id = mysql_insert_id();
header("Location: index.php?id={$id}");
die();
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset ="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1">
<style>
label{ display: block;}
</style>
echo '<ul></ul>' , implode
<title> Add a Post </title>
</head>
<body>
<h1>Add a Post</h1>
<?php
if (isset($errors) && !empty($errors)) {
echo '<ul><li>', implode('</li><li>', $errors), '</li></ul>';
}
?>
<form action='' method="post">
<div>
<label for="title"> Title </label>
<input type="text" name="title" value="<?php if (isset($_POST['title']) ) echo $_POST['title']; ?>">
</div>
<div>
<label for="contents"> Contents </label>
<textarea name="contents" rows="15" cols="50"><?php if (isset($_POST['contents']) ) echo $_POST['contents']; ?></textarea>
</div>
<dir>
<label for="category"> Category </label>
<select name="category">
<?php
foreach (get_categories() as $category) {
?>
<option value="<?php echo $category['id']; ?>"> <?php echo $category['names']; ?> </option>
<?php
}
?>
</select>
</dir>
<dir>
<input type="submit" value="Add Post">
</dir>
</form>
</body>
</html>