/
/
home
/
u523034047
/
domains
/
nainitalfloweritech.com
/
public_html
/
admin
Server: in-mum-web1112.main-hosting.eu (62.72.28.111)
You: 216.73.216.89
PHP 8.3.16
Dir:
/home/u523034047/domains/nainitalfloweritech.com/public_html/admin
Edit:
/home/u523034047/domains/nainitalfloweritech.com/public_html/admin/category.php
<?php session_start(); include('include/config.php'); include('include/admin-menu.php'); if (empty($_SESSION['alogin'])) { header('Location: index.php'); exit(); } date_default_timezone_set('Asia/Kolkata'); /* ===== ADD CATEGORY ===== */ if (isset($_POST['submit'])) { $stmt = $con->prepare( "INSERT INTO category (categoryName, categoryDescription) VALUES (?, ?)" ); $stmt->bind_param("ss", $_POST['category'], $_POST['description']); $_SESSION['msg'] = $stmt->execute() ? "Category created successfully!" : "Failed to create category!"; header("Location: category.php"); exit(); } /* ===== DELETE CATEGORY ===== */ if (isset($_GET['del'], $_GET['id'])) { $id = intval($_GET['id']); $stmt = $con->prepare("DELETE FROM category WHERE id=?"); $stmt->bind_param("i", $id); $_SESSION['delmsg'] = $stmt->execute() ? "Category deleted successfully!" : "Delete failed!"; header("Location: category.php"); exit(); } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Category | Admin</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet"> <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css" rel="stylesheet"> <link href="https://cdn.datatables.net/1.13.6/css/jquery.dataTables.min.css" rel="stylesheet"> <style> body{ background:linear-gradient(135deg,#667eea,#764ba2); min-height:100vh; font-family:'Segoe UI',sans-serif; } .card-box{ background:#fff; border-radius:12px; box-shadow:0 15px 40px rgba(0,0,0,.2); padding:25px; margin-bottom:25px; } .table thead{ background:#4f46e5; color:#fff; } </style> </head> <body> <div class="container py-5"> <!-- 🔹 ADD CATEGORY --> <div class="card-box"> <h4 class="mb-3"><i class="fa fa-folder-plus"></i> Add Category</h4> <?php if(!empty($_SESSION['msg'])){ ?> <div class="alert alert-success text-center"> <?php echo $_SESSION['msg']; $_SESSION['msg']=""; ?> </div> <?php } ?> <form method="post"> <div class="row g-3"> <div class="col-md-6"> <label>Category Name</label> <input type="text" name="category" class="form-control" required> </div> <div class="col-md-6"> <label>Description</label> <textarea name="description" class="form-control" rows="2"></textarea> </div> </div> <button type="submit" name="submit" class="btn btn-primary mt-3"> <i class="fa fa-save"></i> Create Category </button> </form> </div> <!-- 🔹 MANAGE CATEGORY --> <div class="card-box"> <h4 class="mb-3"><i class="fa fa-list"></i> Manage Categories</h4> <?php if(!empty($_SESSION['delmsg'])){ ?> <div class="alert alert-success text-center"> <?php echo $_SESSION['delmsg']; $_SESSION['delmsg']=""; ?> </div> <?php } ?> <table id="categoryTable" class="table table-bordered table-striped"> <thead> <tr> <th>#</th> <th>Category</th> <th>Description</th> <th>Created</th> <th>Updated</th> <th width="120">Action</th> </tr> </thead> <tbody> <?php $q = $con->query("SELECT * FROM category ORDER BY id DESC"); $cnt = 1; while($row = $q->fetch_assoc()){ ?> <tr> <td><?php echo $cnt++; ?></td> <td><?php echo htmlentities($row['categoryName']); ?></td> <td><?php echo htmlentities($row['categoryDescription']); ?></td> <td><?php echo htmlentities($row['creationDate']); ?></td> <td><?php echo htmlentities($row['updationDate']); ?></td> <td> <a href="edit-category.php?id=<?php echo $row['id']; ?>" class="btn btn-sm btn-info"> <i class="fa fa-edit"></i> </a> <a href="category.php?id=<?php echo $row['id']; ?>&del=1" onclick="return confirm('Delete this category?')" class="btn btn-sm btn-danger"> <i class="fa fa-trash"></i> </a> </td> </tr> <?php } ?> </tbody> </table> </div> </div> <script src="https://code.jquery.com/jquery-3.7.1.min.js"></script> <script src="https://cdn.datatables.net/1.13.6/js/jquery.dataTables.min.js"></script> <script> $(document).ready(function(){ $('#categoryTable').DataTable({ pageLength:10, order:[[0,'desc']] }); }); </script> </body> </html>
Ukuran: 4.4 KB