-
Notifications
You must be signed in to change notification settings - Fork 18
/
add-post.php
executable file
·194 lines (176 loc) · 9.3 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
<?php
session_set_cookie_params(0);
session_start();
error_reporting(0);
include('includes/config.php');
if (strlen($_SESSION['login']) == 0) {
header('location: login.php');
} else {
if (isset($_POST['submit'])) {
$title = $_POST['title'];
$cat = $_POST['selectcat'];
$grabber = $_POST['grabber'];
$description = $_POST['description'];
$username = $_POST['name'];
$email3 = $_SESSION['login'];
$sql3 = "SELECT `id` FROM `users` WHERE `email`=:email3";
$query3 = $dbh->prepare($sql3);
$query3->bindParam(':email3', $email3, PDO::PARAM_STR);
$query3->execute();
$results3 = $query3->fetchAll(PDO::FETCH_OBJ);
if ($query3->rowCount() > 0) {
foreach ($results3 as $result3) {
$uid = $result3->id;
}
}
$image1 = $_FILES["img1"]["name"];
$status = 0;
move_uploaded_file($_FILES["img1"]["tmp_name"], "assets/img/postimages/" . $_FILES["img1"]["name"]);
$sql = "INSERT INTO posts(title,category,grabber,description,username,image1,userid,status) VALUES(:title,:cat,:grabber,:description,:username,:image1,:uid,:status)";
$query = $dbh->prepare($sql);
$query->bindParam(':title', $title, PDO::PARAM_STR);
$query->bindParam(':cat', $cat, PDO::PARAM_STR);
$query->bindParam(':grabber', $grabber, PDO::PARAM_STR);
$query->bindParam(':description', $description, PDO::PARAM_STR);
$query->bindParam(':username', $username, PDO::PARAM_STR);
$query->bindParam(':image1', $image1, PDO::PARAM_STR);
$query->bindParam(':uid', $uid, PDO::PARAM_STR);
$query->bindParam(':status', $status, PDO::PARAM_STR);
$query->execute();
$lastInsertId = $dbh->lastInsertId();
if ($lastInsertId) {
echo "<script>alert('Blog submitted successfully, wait for approval');document.location = 'index.php';</script>";
} else {
echo "<script>alert('Something went wrong')</script>";
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
<title>Add Post</title>
<link rel="stylesheet" href="assets/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet"
href="https://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Lora:400,700,400italic,700italic">
<link rel="stylesheet" href="assets/fonts/font-awesome.min.css">
<script src="assets/js/tinymce.min.js" referrerpolicy="origin"></script>
<script>tinymce.init({selector: 'textarea'});</script>
</head>
<body>
<!-- Header -->
<?php include 'includes/header.php'; ?>
<header class="masthead" style="background-image:url('assets/img/home-bg.jpg');">
<div class="overlay"></div>
<div class="container">
<div class="row">
<div class="col-md-10 col-lg-8 mx-auto">
<div class="site-heading">
<h1>Kabir's Blog</h1><span class="subheading">An Informative Blog</span></div>
</div>
</div>
</div>
</header>
<!-- Header -->
<div class="container">
<div class="row">
<div class="col-md-10 col-lg-8 mx-auto">
<h2 class="post-title">Add a post</h2>
<form id="contactForm" method="post" enctype="multipart/form-data">
<div class="control-group">
<div class="form-group floating-label-form-group controls">
<label for="title">Title</label>
<input class="form-control" type="text" id="title" required placeholder="Title"
name="title">
<small class="form-text text-danger help-block">Title</small>
</div>
</div>
<div class="control-group">
<div class="form-group floating-label-form-group controls">
<label for="select1"><strong>Select Category</strong></label>
<select class="form-control" id="select1"
name="selectcat" required>
<option value="">-- Select --</option>
<?php $ret = "SELECT `id`,`catname` FROM `categories`";
$query = $dbh->prepare($ret);
//$query->bindParam(':id',$id, PDO::PARAM_STR);
$query->execute();
$results = $query->fetchAll(PDO::FETCH_OBJ);
if ($query->rowCount() > 0) {
foreach ($results as $result) {
?>
<option value="<?php echo htmlentities($result->id); ?>">
<?php echo htmlentities($result->catname); ?>
</option>
<?php }
} ?>
</select>
<small class="form-text text-danger help-block">Select Category</small>
</div>
</div>
<div class="control-group">
<div class="form-group floating-label-form-group controls">
<label for="grabber">Grabber</label>
<input class="form-control" type="text" id="grabber" required placeholder="Grabber"
name="grabber">
<small class="form-text text-danger help-block">Grabber</small>
</div>
</div>
<div class="control-group">
<div class="form-group floating-label-form-group controls">
<label for="file1">Add an image</label>
<input type="file" class="form-control-file" id="file1" name="img1">
<small class="form-text text-danger help-block">Header Image</small>
</div>
</div>
<div class="control-group">
<div class="form-group floating-label-form-group controls">
<label for="desc">Description</label>
<textarea class="form-control" id="desc" required rows="5"
name="description"></textarea>
<small class="form-text text-danger help-block">Description</small>
</div>
</div>
<?php
$email = $_SESSION['login'];
$sql2 = "SELECT fname,lname,id FROM users WHERE email=:email ";
$query = $dbh->prepare($sql2);
$query->bindParam(':email', $email, PDO::PARAM_STR);
$query->execute();
$results = $query->fetchAll(PDO::FETCH_OBJ);
if ($query->rowCount() > 0) {
foreach ($results as $result2) {
$name = $result2->fname . " " . $result2->lname;
?>
<div class="control-group">
<div class="form-group floating-label-form-group controls">
<label for="name">Username</label>
<input class="form-control" type="text" id="name" required
name="name" value="<?php echo htmlentities($name); ?>">
<small class="form-text text-danger help-block">Username</small>
</div>
</div>
<?php }
}
?>
<br>
<div id="success"></div>
<div class="form-group">
<button class="btn btn-primary float-right" id="sendMessageButton" type="submit"
name="submit">Post
</button>
</div>
</form>
</div>
</div>
</div>
<!-- Footer -->
<?php include 'includes/footer.php'; ?>
<script src="assets/js/jquery.min.js"></script>
<script src="assets/bootstrap/js/bootstrap.min.js"></script>
<script src="assets/js/clean-blog.js"></script>
</body>
</html>
<?php } ?>