Skip to content

Commit

Permalink
CRUD Category
Browse files Browse the repository at this point in the history
  • Loading branch information
ridwanpranata committed Mar 8, 2024
1 parent edddce8 commit 364cd5e
Show file tree
Hide file tree
Showing 8 changed files with 206 additions and 559 deletions.
12 changes: 12 additions & 0 deletions 404.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<div class="row justify-content-center">
<div class="col-lg-6">
<div class="text-center mt-4">
<img class="mb-4 img-error" src="assets/img/error-404-monochrome.svg" />
<p class="lead">This requested URL was not found on this server.</p>
<a href="index.php">
<i class="fas fa-arrow-left me-1"></i>
Return to Dashboard
</a>
</div>
</div>
</div>
40 changes: 40 additions & 0 deletions category.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<h1 class="mt-4">Category</h1>
<ol class="breadcrumb mb-4">
<li class="breadcrumb-item"><a href="index.php">Dashboard</a></li>
<li class="breadcrumb-item active">Tables</li>
</ol>
<div class="card mb-4">
<div class="card-header">
<i class="fas fa-table me-1"></i>
Category List
</div>
<div class="card-body">
<a href="?page=category_add" class="btn btn-primary mb-2"> Add Category</a>
<table id="datatablesSimple" class="table">
<thead>
<tr>
<th>No</th>
<th>Category</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
$i = 1;
$query = mysqli_query($connection, "select * from category");
while( $data = mysqli_fetch_array($query)){ ?>
<tr>
<td><?php echo $i++ ?></td>
<td><?php echo $data['category'] ?></td>
<td>
<a href="?page=category_edit&id=<?php echo $data['id']?>" class="btn btn-sm btn-primary">Edit</a>
<a href="?page=category_delete&id=<?php echo $data['id']?>" class="btn btn-sm btn-danger" onclick="return confirm('Want to Delete?')">Delete</a>
</td>
</tr>

<?php }
?>
</tbody>
</table>
</div>
</div>
35 changes: 35 additions & 0 deletions category_add.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<h1 class="mt-4">Category</h1>
<ol class="breadcrumb mb-4">
<li class="breadcrumb-item"><a href="index.php">Dashboard</a></li>
<li class="breadcrumb-item"><a href="category.php">Category</a></li>
<li class="breadcrumb-item active">Add</li>
</ol>
<div class="card mb-4">
<div class="card-header">
<i class="fas fa-plus me-1"></i>
Add Category
</div>
<div class="card-body">
<?php
if(isset($_POST['submit'])) {
$category = $_POST['category'];
$query = mysqli_query($connection, "INSERT INTO category (category) VALUES ('$category')");
if($query) {
echo '<script> alert("Success Add new Category!"); location.href="?page=category" </script>';
} else {
echo '<script> alert("Failed Add new Category!") </script>';
}
}
?>
<form method="post">
<div class="row">
<div class="col-sm-3">Category Name</div>
<div class="col-sm-9"><input name="category" type="text" class="form-control"></div>
</div>
<div class="d-flex justify-content-end mt-3">
<a href="?page=category" class="btn btn-secondary" style="margin-right:10px;">Cancel</a>
<button class="btn btn-primary" name="submit" value="submit">Add</button>
</div>
</form>
</div>
</div>
11 changes: 11 additions & 0 deletions category_delete.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

$id = $_GET['id'];
$query = mysqli_query($connection, "DELETE FROM category WHERE id='$id'");

?>

<script>
alert('Successfully deleted');
location.href="?page=category"
</script>
41 changes: 41 additions & 0 deletions category_edit.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<h1 class="mt-4">Category</h1>
<ol class="breadcrumb mb-4">
<li class="breadcrumb-item"><a href="index.php">Dashboard</a></li>
<li class="breadcrumb-item"><a href="category.php">Category</a></li>
<li class="breadcrumb-item active">Edit</li>
</ol>
<div class="card mb-4">
<div class="card-header">
<i class="fas fa-plus me-1"></i>
Edit Category
</div>
<div class="card-body">
<?php
$id = $_GET['id'];
if(isset($_POST['submit'])) {

$category = $_POST['category'];
$query = mysqli_query($connection, "UPDATE category SET category='$category' WHERE id = '$id'");
if($query) {
echo '<script> alert("Success Update new Category!"); location.href="?page=category" </script>';
} else {
echo '<script> alert("Failed Update new Category!") </script>';
}
}

$query = mysqli_query($connection, "SELECT * FROM category WHERE id = '$id'");
$data = mysqli_fetch_array($query);

?>
<form method="post">
<div class="row">
<div class="col-sm-3">Category Name</div>
<div class="col-sm-9"><input name="category" type="text" class="form-control" value="<?php echo $data['category']?>"></div>
</div>
<div class="d-flex justify-content-end mt-3">
<a href="?page=category" class="btn btn-secondary" style="margin-right:10px;">Cancel</a>
<button class="btn btn-primary" name="submit" value="submit">Add</button>
</div>
</form>
</div>
</div>
54 changes: 54 additions & 0 deletions home.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<h1 class="mt-4">Dashboard</h1>
<ol class="breadcrumb mb-4">
<li class="breadcrumb-item active">Dashboard</li>
</ol>
<div class="row">
<div class="col-xl-3 col-md-6">
<div class="card bg-primary text-white mb-4">
<?php
$total_user = mysqli_num_rows(mysqli_query($connection, "SELECT * FROM user"));
?>
<div class="card-body">Total User = <?php echo $total_user?></div>
<div class="card-footer d-flex align-items-center justify-content-between">
<a class="small text-white stretched-link" href="#">View Details</a>
<div class="small text-white"><i class="fas fa-angle-right"></i></div>
</div>
</div>
</div>
<div class="col-xl-3 col-md-6">
<div class="card bg-warning text-white mb-4">
<?php
$total_book = mysqli_num_rows(mysqli_query($connection, "SELECT * FROM book"));
?>
<div class="card-body">Total Buku = <?php echo $total_book?></div>
<div class="card-footer d-flex align-items-center justify-content-between">
<a class="small text-white stretched-link" href="#">View Details</a>
<div class="small text-white"><i class="fas fa-angle-right"></i></div>
</div>
</div>
</div>
<div class="col-xl-3 col-md-6">
<div class="card bg-success text-white mb-4">
<?php
$total_category = mysqli_num_rows(mysqli_query($connection, "SELECT * FROM category"));
?>
<div class="card-body">Total Category = <?php echo $total_category?></div>
<div class="card-footer d-flex align-items-center justify-content-between">
<a class="small text-white stretched-link" href="#">View Details</a>
<div class="small text-white"><i class="fas fa-angle-right"></i></div>
</div>
</div>
</div>
<div class="col-xl-3 col-md-6">
<div class="card bg-danger text-white mb-4">
<?php
$total_review = mysqli_num_rows(mysqli_query($connection, "SELECT * FROM review"));
?>
<div class="card-body">Total = <?php echo $total_review?></div>
<div class="card-footer d-flex align-items-center justify-content-between">
<a class="small text-white stretched-link" href="#">View Details</a>
<div class="small text-white"><i class="fas fa-angle-right"></i></div>
</div>
</div>
</div>
</div>
Loading

0 comments on commit 364cd5e

Please sign in to comment.