AlexWebDevelop

Untitled

Jun 21st, 2020
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. if(isset($_POST['save'])){
  4.     $checkbox = NULL;
  5.    
  6.     if (isset($_POST['check']))
  7.     {
  8.         $checkbox = $_POST['check'];
  9.     }
  10.    
  11.     if (is_array($checkbox))
  12.     {
  13.         $checkboxCount = count($checkbox);
  14.        
  15.         for($i=0; $i < $checkboxCount; $i++)
  16.         {
  17.             /*  IMPORTANT:
  18.                 You need to validate each $checkbox item to make sure:
  19.                 - it is a valid int number
  20.                 - the current user has permission to delete it
  21.             */
  22.            
  23.             $del_id = $checkbox[$i];
  24.            
  25.             /* Make sure $del_id is a valid int. You should also check that is a correct database ID. */
  26.             if (filter_var($del_id, FILTER_VALIDATE_INT))
  27.             {
  28.                 mysqli_query($link,"DELETE FROM admin WHERE id='".mysqli_real_escape_string($link, $del_id)."'");
  29.             }
  30.         }
  31.        
  32.         $message = "Data deleted successfully !";
  33.     }
  34.     else
  35.     {
  36.         $message = "No data selected!";
  37.     }
  38. }
  39.  
  40. $result = mysqli_query($link,"SELECT * FROM admin LIMIT $offset,$total_records_per_page");
  41. ?>
  42. <!DOCTYPE html>
  43. <html>
  44. <head>
  45. <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  46. <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  47.  
  48.  
  49. <style><?php include 'Backend.css'; ?></style>
  50.  
  51.     <meta charset="UTF-8">
  52.     <title>Dashboard</title>
  53.     <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.css">
  54.     <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
  55.     <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
  56.     <script src='https://kit.fontawesome.com/a076d05399.js'></script>
  57.     <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
  58.  
  59. </head>
  60. <body>
  61.  
  62.  
  63.  
  64. <div><?php if(isset($message)) { echo $message; } ?>
  65. </div>
  66. <div class="container">
  67.  
  68. <form method="post" action="admin.php">
  69. <table class="table table-bordered" id="myTables">
  70. <thead>
  71. <tr>
  72.     <th><input type="checkbox" id="checkAl"> Select All</th>
  73.     <th>Admin Id</th>
  74.     <th>Username</th>
  75.     <th>Email</th>
  76.     <th>Password</th>
  77.     <th>Action</th>
  78. </tr>
  79. </thead>
  80. <?php
  81. $i=0;
  82. while($row = mysqli_fetch_array($result)) {
  83. ?>
  84. <tr>
  85.     <td><input type="checkbox" id="checkItem" name="check[]" value="<?php echo $row["id"]; ?>"></td>
  86.     <td><?php echo $row["id"]; ?></td>
  87.  
  88.     <td><?php echo $row["username"]; ?></td>
  89.     <td><?php echo $row["email"]; ?></td>
  90.     <td><?php echo $row["password"]; ?></td>
  91. <?Php
  92.                                             echo "<td>";
  93.  
  94.     echo "<a href='Admin-View.php?id=". $row['id'] ."' title='View Record' data-toggle='tooltip'><span class='glyphicon glyphicon-eye-open'></span></a>";
  95.                                             echo "<a href='Admin-Update.php?id=". $row['id'] ."' title='Update Record' data-toggle='tooltip'><span class='glyphicon glyphicon-pencil'></span></a>";
  96.                                             echo "<a href='Admin-Delete.php?id=". $row['id'] ."' title='Delete Record' data-toggle='tooltip'><span class='glyphicon glyphicon-trash'></span></a>";
  97.  
  98.                                           echo "</td>";
  99.                                           ?>
  100.  
  101.  
  102. </tr>
  103. </div>
  104.             </div>        
  105.         </div>
  106.     </div>
  107.     </div>
  108.  
  109. <?php
  110. $i++;
  111. }
  112. ?>
  113. </table>
  114.  <input type="submit" name="submit" value="Delete" class="btn btn-primary btn-md pull-left" onClick="return confirm('Are you sure you want to delete?');" ></td>
  115. </form>
  116.  
  117.  
  118. <script>
  119. $("#checkAl").click(function () {
  120. $('input:checkbox').not(this).prop('checked', this.checked);
  121. });
  122.  
  123.  
  124. </script>
  125. </body>
  126. </html>
Add Comment
Please, Sign In to add comment