-
Notifications
You must be signed in to change notification settings - Fork 7
/
insert_post.php
212 lines (135 loc) · 5.17 KB
/
insert_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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
<script src="js/tinymce/tinymce.min.js">
</script>
<script>
tinymce.init({selector:'textarea'});
</script>
<?php
include'core/init.php';
protect_page();
?>
<?php include'includes/overall/header.php';
if(empty($_POST)===false){
$required_fields=array('post_title','post_author','post_keywords','post_image','post_content','post_cat');
//echo '<pre>',print_r($_POST,true),'</pre>'; Testing line
foreach($_POST as $key=>$value){
if(empty($value)&&in_array($value,$required_fields)===true){
$errors[]='Field Marked with asteriks are required.';
break 1;//it will come out of this loop abnd continue the execution.
}
}
if (empty($errors)===true){
/*
if(user_exists($a) === 1||user_exists($c) >1){
$errors[]='Sorry, The Username \''.htmlentities($_POST['username']).'\' is already taken.';
}
if(preg_match("/\\s/",$_POST['username'])==true){
//$regular_expression=preg_match("/\\s/",$_POST['username']);
//var_dump($regular_expression); This pregmatch return 1 if the statement is true.
$errors[]='Sorry, The Username \''.htmlentities($_POST['username']).'\' Contains space.We don\'t allow spaces in username';
}
if(email_exists($c) === 1||email_exists($c) >1){
$errors[]='Sorry, The email id \''.htmlentities($_POST['email']).'\' is already in use.';
}
if(strlen($_POST['password'])<6){
$errors[]='Sorry, The password must be atleast 6 characters';
}
if(strlen($_POST['password'])>30){
$errors[]='Sorry, The password can be atmax 30 characters';
}
if($_POST['password']!== $_POST['repeatpassword']){
$errors[]='Sorry, The password didn\'t matched.';
}
if(filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)===false){
$errors[]='A valid Email address is required.';
}
if($_POST['gender']==='male'){
$profilepic="images/profile/defaultmale.jpg";
}
else if($_POST['gender']==='female'){
$profilepic="images/profile/defaultfemale.jpg";
}
*/
}
}
?>
<h1>Insert New Post</h1>
<?php
if(isset($_GET['success'])&&empty($_GET['success'])){
echo 'Post has been published successfully.';
}
else{
if(empty($errors)=== true && empty($_POST)===false){
$post_image=$_FILES['post_image']['name'];
$post_image_tmp=$_FILES['post_image']['tmp_name'];
$insert_data=array(
'post_title' => $_POST['post_title'],
'post_date' => $post_date,
'post_author' => $_POST['post_author'],
'post_keywords' => $_POST['post_keywords'],
'post_image' => $_FILES['post_image']['name'],
'post_content' => $_POST['post_content'],
'category_id' => $_POST['post_cat']
);
move_uploaded_file($post_image_tmp,"../images/$post_image");
insert_post($insert_data);
/*$insert_posts="insert into posts (category_id,post_title,post_date,post_author,post_keywords,post_image,post_content) values ('$post_cat','$post_title','$post_date','$post_author',
'$post_keywords','$post_image','$post_content')";
$run_insert=mysqli_query($insert_posts);
if(mysqli_query($run_posts)){
echo "<script>alert('Post has been published')</script>";
echo "<script>window.open('insert_post.php','_self')</script>";
}*/
header('Location:insert_post.php?success');
exit();
}
else if(empty($errors)=== false){
?>
<h2>We tried to Publish the post, but</h2>
<?php
echo output_errors($errors);
}
?>
<form action=" " method="POST"name="RegisterForm" id="RegisterForm">
<ul id= "registerform" style="list-style: none;">
<h1>Insert New Post</h1>
<li>Post title*: <br>
<input type="text" name="post_title" required="required"
class="tfield" id="username" placeholder="User Name">
</li><br>
<li>Post Category*: <br>
<select name="post_cat" required="required">
<option>Select a category</option>
<?php
$cong=mysqli_connect("localhost","root","","mycms");
$get_cats="select * from catagories";
$run_cats=mysqli_query($cong,$get_cats);
while($cats_row=mysqli_fetch_array($run_cats)){
$cat_id=$cats_row['cat_id'];
$cat_title=$cats_row['cat_title'];
echo "<option value='$cat_id'>$cat_title</option>";
}
?>
</select>
</li><br>
<li>Post Author*: <br>
<input type="text" name="post_author" required="required"
class="tfield" id="gender" placeholder="Gender">
</li><br>
<li>Post Keywords*: <br>
<input type="text" name="post_keywords" required="required"
class="tfield" id="age" placeholder="Age">
</li><br>
<li>Post Image*: <br>
<input type="file" name="post_image" size="50" required="required" /></li><br>
<li>Post Content* :<br>
<textarea name="post_content" rows="15" cols="40" required="required" ></textarea>
</li><br>
<li><br>
<input type="submit" value="Publish Now" >
</li><br>
</ul>
</form>
</form>
<?php
}
include 'includes/overall/footer.php';?>