-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnewPost.php
147 lines (143 loc) · 5.51 KB
/
newPost.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
<?php
session_start();
require_once './include/connection.php' ;
require_once './include/header.php';
$message = false;
if(isset($_POST['save'])){
$imageName = $_FILES["postImage"]["name"];
$imageTMP = $_FILES["postImage"]["tmp_name"];
$title = filter_input(INPUT_POST , 'post-title' , FILTER_SANITIZE_STRING);
$pContent = filter_var($_POST['postContent'] , FILTER_SANITIZE_STRING);
$categorie =filter_var($_POST['category'] , FILTER_SANITIZE_STRING);
$pWriter = "انس شلبي يوسف";
if(empty($title) || empty($pContent)){
$_SESSION['message'] = 'برجاء ملئ الفورم';
}elseif(strlen($pContent) > 1000){
$_SESSION['message'] = 'لقد تعديت الحد الاقصي';
}else {
$postImage = rand(0,1000) ."_" .$imageName;
move_uploaded_file($imageTMP , "uploads". DIRECTORY_SEPARATOR .'postImage'.DIRECTORY_SEPARATOR.$postImage);
$query = "INSERT INTO posts (postTitle , categorie,postImage,postContent , writer) VALUES ('$title' , '$categorie' ,'$postImage' ,'$pContent' , '$pWriter')";
$res = mysqli_query($connection , $query);
if(isset($res)){
$_SESSION['message'] = 'تمت الاضافه بجاح';
$message = true;
}else {
$_SESSION['message'] = "حدث خطا ما";
}
}
}
?>
<!-- START CONTENT -->
<div class="content">
<div class="container-fluid">
<div class="row">
<div class="col-md-2 nav-light bg-dark" id="side-area">
<h4>لوحة التحكم</h4>
<div class='text-center Admin'>
<img class="rounded-circle" src="./images/twiter.jpg" width='80px' height="80px"></img>
<h5 > مدير تطبيق </h5>
</div>
<ul>
<li>
<a href="./categorie.php">
<span><i class="fas fa-tags"></i></span>
<span>التصنيفات</span>
</a>
</li>
<!-- ARTICLES -->
<li data-toggle="collapse" data-target="#menu">
<a href="#">
<span><i class="fa-solid fa-newspaper"></i></span>
<span>المقالات</span>
</a>
</li>
<ul class="collapse" id="menu">
<li>
<a href="#">
<span><i class="fa-solid fa-plus"></i></span>
<span> مقال جديد</span>
</a>
</li>
<li>
<a href="posts.php">
<span><i class="fa-solid fa-pager"></i></span>
<span> كل المقالات</span>
</a>
</li>
</ul>
<li>
<a href="index.php" target="_blank">
<span><i class="fa-solid fa-house"></i></span>
<span>عرض الموقع</span>
</a>
</li>
<li>
<a href="#">
<span
><i class="fa-solid fa-arrow-right-from-bracket"></i
></span>
<span>تسجيل الخروج</span>
</a>
</li>
</ul>
</div>
<div class="col-md-10" id="main-area">
<div class="add-categorie">
<form action="<?php $_SERVER['PHP_SELF'] ?>" method='post' enctype="multipart/form-data">
<?php
if(isset($_POST['save'])){
?>
<p class="<?= $message ? "bg-success text-light p-2 text-center":"bg-danger text-light p-2 text-center" ?>"> <?= $_SESSION['message'] ?> </p>
<?php
}
?>
<div class="form-group">
<label for="categorie">عنوان المقال</label>
<input
type="text"
name="post-title"
class="form-control"
id="categorie"
/>
</div>
<div class="form-group">
<label for="cat">التصنيف</label>
<select name="category" id="cat" class="form-select">
<?php
$query1 = "SELECT * FROM categories";
$res1 =mysqli_query($connection , $query1);
while($row = mysqli_fetch_assoc($res1)){
?>
<option><?= $row['categorieName'] ?></option>
<?php
}
?>
</select>
</div>
<div class="form-group">
<label for="image"> صورة المقال </label>
<input type="file" id="image" name='postImage' />
</div>
<div class="form-group">
<label for="content"> محتوى المقال </label>
<textarea
name="postContent"
id=""
cols="30"
rows="10"
class="form-control"
></textarea>
</div>
<button class="btn btn-custom" name="save">نشر</button>
</form>
</div>
</div>
</div>
</div>
</div>
<!-- END CONTENT -->
<?php require_once './include/footer.php';
session_write_close();
session_destroy();
?>