-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaddcategory.php
80 lines (52 loc) · 1.87 KB
/
addcategory.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
<?php
session_start();
if($_SESSION['email']==true){
}else{
header('location:admin_login.php');
}
$page='category';
include('include/header.php');
?>
<div style=" width:70%;margin-left: 25%; margin-top: 10%">
<form action="" name="categoryform" method="post" onsubmit="return validateform()">
<h1>Add Categories</h1><hr>
<div class="form-group">
<label for="email">Category:</label>
<input type="text" name="category" placeholder="Enter Category Name" class="form-control" id="email">
</div>
<div class="form-group">
<label for="comment">Description:</label>
<textarea class="form-control" name="des" placeholder="Enter Category Description" rows="5" id="comment"></textarea>
</div>
<input type="submit" name="submit" class="btn btn-primary" value="Add category">
<script>
function validateform(){
var x = document.forms['categoryform']['category'].value;
if(x==""){
alert('Category must be filled out !');
return false;
}
}
</script>
</div>
<?php
include('include/footer.php');
?>
<?php
include('db/connection.php');
if(isset($_POST['submit'])){
$category_name = $_POST['category'];
$des = $_POST['des'];
$check = mysqli_query($conn,"SELECT * FROM category WHERE category_name='$category_name'");
if(mysqli_num_rows($check)>0){
echo "<script>alert('Category Name Already Exist !')</script>";
exit();
}
$query = mysqli_query($conn,"INSERT INTO category(category_name,des) VALUES ('$category_name','$des')");
if($query){
echo "<script> alert('Category Add Successfuly')</script>";
}else{
echo "<script> alert('Please Try Again !')</script>";
}
}
?>