<!DOCTYPE html>
<html lang="en">
<?php session_start(); ?>
<?php include "../includes/db.php" ?>
<?php include "../admin/includes/header.php" ?>
<?php
if(isset($_POST['edit'])){
$post_id=$_POST['post_id'];
$img_title=$_POST['title'];
$query="UPDATE categories SET title ='{$img_title}' WHERE id={$post_id}";
$result=mysqli_query($connection,$query);
if($result){
$_SESSION['edit_messages'] ="Successfully updated";
}
else{
$_SESSION['edit_messages']="server error";
}
}
if(isset($_GET['delete'])){
$post_id=$_GET['delete'];
$query="DELETE FROM categories WHERE id={$post_id}";
$delete_query=mysqli_query($connection,$query);
if($delete_query){
$_SESSION['edit_messages'] ="Successfully deleted";
}
else{
$_SESSION['edit_messages']="server error";
}
}?>
<body>
<div class="container-scroller">
<?php include "../admin/includes/topbar.php" ?>
<div class="container-fluid page-body-wrapper">
<?php include "../admin/includes/nav.php" ?>
<!-- partial -->
<div class="main-panel">
<div class="content-wrapper">
<div class="page-header">
<h3 class="page-title">Manage Categories</h3>
<nav aria-label="breadcrumb">
</nav>
</div>
<div class="row">
<div class="col-lg-12 grid-margin stretch-card">
<div class="card">
<div class="card-body">
<h4 class="card-title">Category List</h4>
<p class="card-description"></code>
</p>
<?php
if(isset($_SESSION['edit_messages'])){
echo "<div class='alert alert-primary'>";
echo "<span class='glyphicon glyphicon-remove'></span> ".$_SESSION['edit_messages']."<br>";
echo "</div>";
unset($_SESSION['edit_messages']);
}
?>
<table class="table table-bordered" id="gallery">
<thead>
<tr>
<th> # </th>
<th>Title </th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
$query="SELECT * FROM categories";
$result=mysqli_query($connection,$query);
$count=mysqli_num_rows($result);
$i = 0;
while($row=mysqli_fetch_assoc($result)){
$i++;
?>
<tr>
<td> <?php echo $i ?> </td>
<td> <?php echo $row['title'] ?></td>
<td><button class="btn btn-sm btn-primary"><a class="mdi mdi-delete"href="edit_categories.php?edit=<?php echo $row['id'] ?>" style="color:white">Edit</a></button>
<button class="btn btn-sm btn-danger"><a class="mdi mdi-delete"href="view_categories.php?delete=<?php echo $row['id'] ?>" style="color:white">Delete</a></button>
</td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- main-panel ends -->
</div>
<!-- page-body-wrapper ends -->
</div>
<!-- container-scroller -->
<!-- plugins:js -->
<script src="./vendors/js/vendor.bundle.base.js"></script>
<!-- endinject -->
<script src="./vendors/typeahead.js/typeahead.bundle.min.js"></script>
<!-- End plugin js for this page -->
<!-- inject:js -->
<script src="./js/misc.js"></script>
<!-- endinject -->
<!-- Custom js for this page -->
<script src="./js/typeahead.js"></script>
<script src="./js/jquery.dataTables.min.js"></script>
<!-- End custom js for this page -->
<script type="text/javascript">
$(document).ready( function () {
$('.table').DataTable({
// scrollY: '100px',
});
} );
</script>
</body>
</html> |