-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaddnews.php
154 lines (105 loc) · 4.01 KB
/
addnews.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
<?php
session_start();
if($_SESSION['email']==true){
}else{
header('location:admin_login.php');
}
$page='category';
include('include/header.php');
?>
<div style="width: 80%; margin-left:16% ">
<ul class="breadcrumb">
<li class="breadcrumb-item active"><a href="home.php">Home</a></li>>
<li class="breadcrumb-item active"><a href="news.php">News</a></li>>
<li class="breadcrumb-item active">Add News</li>>
</ul>
</div>
<div style=" width:70%;margin-left: 25%; margin-top: 10%">
<form action="" name="categoryform" method="post" enctype="multipart/form-data" onsubmit="return validateform()">
<h1>Add News</h1><hr>
<div class="form-group">
<label for="email">Title:</label>
<input type="text" name="title" placeholder="Title Name" class="form-control" id="email">
</div>
<div class="form-group">
<label for="comment">Description:</label>
<textarea class="form-control" name="description" placeholder=" Description" rows="5" id="comment"></textarea>
</div>
<div class="form-group">
<label for="email">Date:</label>
<input type="date" name="date" class="form-control" id="email">
</div>
<div class="form-group">
<label for="email">Date:</label>
<input type="file" name="thumbnail" class="form-control img img-thumbnail" id="email">
</div>
<div class="form-group">
<label for="email">Category:</label>
<select class="form-control" name="category">
<?php
include('db/connection.php');
$query = mysqli_query($conn,"SELECT * FROM category");
while($row=mysqli_fetch_array($query)){
$category =$row['category_name'];
?>
<option><?php echo $category;?></option>
<?php }?>
</select>
</div>
<div class="form-control">
<label for="admin">Admin</label>
<input type="text" class="form-control" disabled value="<?php echo $_SESSION['email'];?>">
</div>
<input type="submit" name="submit" class="btn btn-primary" value="submit">
</form>
<script>
function validateform(){
var x = document.forms['categoryform']['title'].value;
var y = document.forms['categoryform']['description'].value;
var z = document.forms['categoryform']['date'].value;
var w = document.forms['categoryform']['category'].value;
if(x==""){
alert('Title must be filled out !');
return false;
}
if(y==""){
alert('Description must be filled out !');
return false;
}
if(y.length<10){
alert('Description Atleast 100 character !');
return false;
}
if(z==""){
alert('Date must be filled out !');
return false;
}
if(w==""){
alert('Category must be filled out !');
return false;
}
}
</script>
</div>
<?php
include('include/footer.php');
?>
<?php
include('db/connection.php');
if(isset($_POST['submit'])){
$title = $_POST['title'];
$description = $_POST['description'];
$date = $_POST['date'];
$thumbnail = $_FILES['thumbnail']['name'];
$tmp_thumbnail = $_FILES['thumbnail']['tmp_name'];
$category = $_POST['category'];
$admin = $_SESSION['email'];
move_uploaded_file($tmp_thumbnail, "images/$thumbnail");
$query2 = mysqli_query($conn,"INSERT INTO news(title,description,date,category,thumbnail,admin) VALUES ('$title','$description','$date','$category','$thumbnail','$admin')");
if($query2){
echo "<script> alert('News uploaded sucessfully');</script>";
}else{
echo "<script> alert('Please , Try Again !');</script>";
}
}
?>