-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate.post.php
76 lines (64 loc) · 2.37 KB
/
create.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
<?php
// Connect to db
require 'engine/connection.php';
// Checks for login
if(!is_logged_in() ){
header('Location: /');
die();
}
if ( $_SERVER['REQUEST_METHOD'] === 'POST' ) {
$title = trim(htmlentities($_POST['title']));
$body = $_POST['body'];
$name = trim(htmlentities($_POST['name']));
$email = trim(htmlentities($_POST['email']));
$category = trim(htmlentities($_POST['category']));
if( empty($title) || empty($body) || empty($name)) {
$status = 'Please fill out all Fields.';
} else {
query(
"INSERT INTO posts(title, name, email, body, category, created_at) VALUES(:title, :name, :email,:body, :category,CURRENT_DATE())",
array( 'title' => $title,
'name' => $name,
'email' => $email,
'body' => $body,
'category' => $category),
$conn);
$status = header('Location:index.php');
}
}
?>
<!DOCTYPE HTML>
<html>
<head>
<?= head('New Post') ?>
</head>
<body>
<div class="pure-g" id="layout">
<?php include 'includes/header.inc.php'; ?>
<div class="content pure-u-1 pure-u-med-3-4">
<div class="container">
<form action="" id="form" class="pure-form pure-form-stacked" method="POST">
<fieldset>
<legend>Create A New Post</legend>
<label for="name">Full Name :</label>
<input type="text" class="pure-input-1" name="name" id="name" placeholder="Enter your name" autofocus required>
<label for="email">Email :</label>
<input type="email" class"pure-input-1" name="email" id="email" pattern="[^ @]*@[^ @]*\.[a-zA-z]{2,}" placeholder="Enter your email address" required>
<label for="title">Title :</label>
<input type="text" class="pure-input-1" name="title" id="title" placeholder="Enter title for your blogpost" required>
<label for="category">Category :</label>
<input type="text" class="pure-input-1" name="category" id="category" placeholder="Enter Category Name for your post" required>
<label for="body">Body :</label>
<textarea name="body" class="pure-input-1" id="body" placeholder="Enter your post description" required></textarea>
<button type="submit" name="submit" class="pure-button">Post</button>
<?php if ( isset($status) ) : ?>
<p class="error"><?= $status; ?></p>
<?php endif; ?>
</fieldset>
</form>
</div>
<?php include 'includes/footer.inc.php'; ?>
</div>
</div>
</body>
</html>