-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcategory.php
More file actions
156 lines (146 loc) · 6.12 KB
/
category.php
File metadata and controls
156 lines (146 loc) · 6.12 KB
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
<?php
include 'functions/config.php';
session_start();
if($_SESSION['userEmail'] == '' || $_SESSION['userRole'] == 'User'){
header('location: index.php');
}
include 'includes/head.php';
include 'includes/preloader.php';
include 'includes/navbar.php';
include 'includes/sidebar.php';
if(isset($_POST['submit'])){
$category_name = $_POST['category'];
$sqlCheck = "SELECT category_name FROM category WHERE category_name = :cat_name ";
$queryCheck = $pdo->prepare($sqlCheck);
$queryCheck->bindParam(':cat_name', $category_name);
$queryCheck->execute();
if($queryCheck->rowCount() > 0){
echo '<script type="text/javascript">
jQuery(function validation(){
Swal.fire({
title: "Oops ! '.strtoupper($_SESSION['userName']).'",
icon: "error",
html:
"<h1>Category Already Exists !</h1>",
confirmButtonText:
"Back",
})
});
</script>';
} else {
$sqlInsert = "INSERT INTO category (category_name) VALUES(:cat_name)";
$queryInsert = $pdo->prepare($sqlInsert);
$queryInsert->bindParam(':cat_name', $category_name);
$result = $queryInsert->execute();
if($result){
echo '<script type="text/javascript">
jQuery(function validation(){
Swal.fire({
title: "Good Job! '.strtoupper($_SESSION['userName']).'",
icon: "success",
html:
"<h1>New Category Created !</h1>",
confirmButtonText:
"Ok",
})
});
</script>';
} else {
echo "<p class='alert alert-danger text-uppercase'>Query Failed: data not inserted </p>";
}
}
}
?>
<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
<!-- Content Header (Page header) -->
<div class="content-header">
<div class="container-fluid">
<div class="row mb-2">
<div class="col-sm-6">
<h1 class="m-0">Dashboard</h1>
</div><!-- /.col -->
<div class="col-sm-6">
<ol class="breadcrumb float-sm-right">
<li class="breadcrumb-item"><a href="#">Home</a></li>
<li class="breadcrumb-item active">Dashboard</li>
</ol>
</div><!-- /.col -->
</div><!-- /.row -->
</div><!-- /.container-fluid -->
</div>
<!-- dashboard main content Start -->
<section class="content">
<!-- general form elements -->
<div class="row">
<div class="col-md-4">
<div class="card card-warning">
<div class="card-header">
<h3 class="card-title text-white">Add Category</h3>
</div>
<form action="<?php $_SERVER['PHP_SELF']?>" method="post">
<!-- card body -->
<div class="card-body pb-0">
<div class="form-group">
<label for="category">Category Name</label>
<input type="text" class="form-control" name="category" id="category" placeholder="Enter Category" >
</div>
</div>
<!-- card footer -->
<div class="card-footer pt-0 bg-dark">
<button type="submit" name="submit" class="btn btn-info">Submit</button>
</div>
</form>
</div>
</div>
<div class="col-md-8">
<div class="card card-warning">
<table class="table table-bordered responsive">
<div class="card-header">
<h3 class="card-title text-center text-white">All Categories</h3>
<thead>
<tr>
<th style="width: 10px">#</th>
<th>Category Name</th>
<th>Edit</th>
<th style="width: 40px">Delete</th>
</tr>
</thead>
</div>
<!-- card body -->
<div class="card-body p-0">
<tbody>
<?php
$sqlSelect = "SELECT * FROM category";
$querySelect = $pdo->prepare($sqlSelect);
$querySelect->execute();
$sl = 1;
while($row = $querySelect->fetch(PDO::FETCH_OBJ)){
?>
<tr>
<td><?php echo $sl++ ?></td>
<td><?php echo $row->category_name ?></td>
<td>
<a href="category.php?<?php echo base64_encode($row->category_name) ?>=<?php echo $row->cat_id?>">
<button class="btn btn-sm btn-success" name="edit">button</button>
</a>
</td>
<td>
<a href="category.php?<?php echo base64_encode($row->category_name) ?>=<?php echo $row->cat_id?>">
<button class="btn btn-sm btn-danger" name="delete">delete</button>
</a>
</td>
</tr>
<?php
}
?>
</tbody>
</div>
</table>
</div>
</div>
</div>
</section>
<!-- main content End -->
</div>
<?php include 'includes/footer.php'; ?>