Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.31 KB | None | 0 0
  1. <html>
  2. <?php include("includes/admin_header.php"); ?>
  3. <h1>Welcome to Admin Page</h1>
  4. <hr>
  5.  
  6. <table class="table table-bordered">
  7. <thead class="thead-dark">
  8. <tr>
  9. <th>ID</th>
  10. <th>Category Name</th>
  11. <th>Add - Edit - Delete</th>
  12. </tr>
  13. </thead>
  14. <tbody>
  15. <?php
  16. //delete function
  17. if(isset($_GET["delete"])){
  18. $del_cat_id = htmlspecialchars($_GET["delete"]);
  19.  
  20. $sql_query = "DELETE FROM categories WHERE category_id = {$del_cat_id}";
  21.  
  22. $delete_category_query = mysqli_query($conn, $sql_query);
  23.  
  24. header("Location: categories.php");
  25.  
  26. }
  27. ?>
  28. <?php
  29. //Edit category
  30. if(isset($_POST["edit_category"])){
  31. $edit_cat_title = $_POST["category_namex"];
  32.  
  33. $sql_query_edit = "UPDATE categories SET category_name = '$edit_cat_title' WHERE
  34. category_id = '$_POST[category_id];'";
  35.  
  36. $edit_category_query = mysqli_query($conn,$sql_query_edit);
  37. header("Location: categories.php");
  38. }
  39. ?>
  40. <?php
  41. //posting
  42. if(isset($_POST["add_category"])){
  43. $category_name = htmlspecialchars($_POST["category_name"]);
  44.  
  45. if($category_name == "" || empty($category_name)){
  46. echo '<div class="alert alert-danger" role="alert">
  47. please do not leave blank lines!
  48. </div>';
  49. }else{
  50. $sql_query = "INSERT INTO categories(category_name) VALUE('$category_name')";
  51. $add_new_category_query = mysqli_query($conn, $sql_query);
  52. echo '<div class="alert alert-success" role="alert">
  53. New Category Added!
  54. </div>';
  55. }
  56.  
  57. }
  58. ?>
  59.  
  60.  
  61. <?php
  62. //selecting
  63. $sql_query = "SELECT * FROM categories ORDER BY category_id DESC";
  64. $select_all_categories = mysqli_query($conn, $sql_query);
  65. $k = 1;
  66. $k++;
  67. while($row = mysqli_fetch_assoc($select_all_categories)){
  68. $category_id = htmlspecialchars($row["category_id"]);
  69. $category_name = htmlspecialchars($row["category_name"]);
  70. echo "<tr>
  71. <td>{$category_id}</td>
  72. <td>{$category_name}</td>
  73. <td>
  74. <div class='dropdown'>
  75. <button class='btn btn-primary dropdown-toggle' type='button' id='dropdownMenuButton' data-toggle='dropdown' aria-haspopup='true' aria-expanded='false'>
  76. Actions
  77. </button>
  78. <div class='dropdown-menu' aria-labelledby='dropdownMenuButton'>
  79. <a class='dropdown-item' data-toggle='modal' data-target='#edit_modal$k' href='#'>Edit</a>
  80. <div class='dropdown-divider'></div>
  81. <a class='dropdown-item' href='categories.php?delete={$category_id}'>Delete</a>
  82. <div class='dropdown-divider'></div>
  83. <a class='dropdown-item' href='#' data-toggle='modal' data-target='#add_modal'>Add</a>
  84. </div>
  85. </div>
  86. </td>
  87. </tr>";
  88. }
  89. ?>
  90.  
  91.  
  92.  
  93. <div id="edit_modal<?php echo $k ?>" class="modal fade">
  94. <div class="modal-dialog" role="document">
  95. <div class="modal-content">
  96. <div class="modal-header">
  97. <h5 class="modal-title" id="exampleModalLabel">Edit Category</h5>
  98. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  99. <span aria-hidden="true">&times;</span>
  100. </button>
  101. </div>
  102. <div class="modal-body">
  103. <form action="" method="post">
  104. <div class="form-group">
  105.  
  106. <input value="<?php if(isset($category_name)) {echo $category_name ;} ?>" type="text" class="form-control" name="category_namex">
  107. </div>
  108. <div class="form-group">
  109. <input type="hidden" name="category_id" value="<?php echo $category_id ?>">
  110. <input type="submit" class="btn btn-primary" name="edit_category" value="Edit Category">
  111. </div>
  112. </form>
  113. </div>
  114. </div>
  115. </div>
  116. </div>
  117. </tbody>
  118. </table>
  119.  
  120. <div id="add_modal" class="modal fade">
  121. <div class="modal-dialog" role="document">
  122. <div class="modal-content">
  123. <div class="modal-header">
  124. <h5 class="modal-title" id="exampleModalLabel">Add New Category</h5>
  125. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  126. <span aria-hidden="true">&times;</span>
  127. </button>
  128. </div>
  129. <div class="modal-body">
  130. <form action="" method="post">
  131. <div class="form-group">
  132. <input type="text" class="form-control" name="category_name">
  133. </div>
  134. <div class="form-group">
  135. <input type="submit" class="btn btn-primary" name="add_category" value="Add Category">
  136. </div>
  137. </form>
  138. </div>
  139. </div>
  140. </div>
  141. </div>
  142.  
  143.  
  144.  
  145.  
  146. <?php include("includes/admin_footer.php"); ?>
  147.  
  148. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement