Guest User

PHP issue

a guest
May 18th, 2016
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.35 KB | None | 0 0
  1. I need some help with this. I am trying to update the column to 'complete' when the check box is checked. What is wrong in my code?
  2.  
  3.  
  4. action.php:
  5.  
  6. <?php
  7. session_start();
  8. include_once('dbConfig.php');
  9. if(isset($_POST['bulk_UPDATE_submit'])){
  10.     $idArr = $_POST['checked_id'];
  11.     foreach($idArr as $id){
  12.         mysqli_query($conn,"UPDATE learning_scorm_tracking SET lesson_status = 'incomplete' WHERE idscorm_tracking=".$id);
  13.     }
  14.     $_SESSION['success_msg'] = 'Users have been UPDATED successfully.';
  15.     header("Location:index.php");
  16. }
  17.  
  18. ?>
  19.  
  20. index.php:
  21.  
  22. <!DOCTYPE html>
  23. <html>
  24. <head>
  25. <title>Delete multiple rows in PHP by CodexWorld</title>
  26. <link rel="stylesheet" href="style.css"/>
  27. <script type="text/javascript" src="jquery.min.js"></script>
  28. <script type="text/javascript">
  29. function update_confirm(){
  30.     var result = confirm("Are you sure to update student?");
  31.     if(result){
  32.         return true;
  33.     }else{
  34.         return false;
  35.     }
  36. }
  37.  
  38. $(document).ready(function(){
  39.     $('#select_all').on('click',function(){
  40.         if(this.checked){
  41.             $('.checkbox').each(function(){
  42.                 this.checked = true;
  43.             });
  44.         }else{
  45.              $('.checkbox').each(function(){
  46.                 this.checked = false;
  47.             });
  48.         }
  49.     });
  50.    
  51.     $('.checkbox').on('click',function(){
  52.         if($('.checkbox:checked').length == $('.checkbox').length){
  53.             $('#select_all').prop('checked',true);
  54.         }else{
  55.             $('#select_all').prop('checked',false);
  56.         }
  57.     });
  58. });
  59. </script>
  60. </head>
  61.  
  62. <body>
  63.  
  64. <?php session_start(); if(!empty($_SESSION['success_msg'])){ ?>
  65. <div class="alert alert-success"><?php echo $_SESSION['success_msg']; ?></div>
  66. <?php unset($_SESSION['success_msg']); } ?>
  67. <?php
  68. include_once('dbConfig.php');
  69. $query = mysqli_query($conn,"SELECT * FROM learning_scorm_tracking WHERE lesson_status = 'completed'");
  70. ?>
  71. <form name="bulk_action_form" action="action.php" method="post" onSubmit="return update_confirm();"/>
  72.     <table class="bordered">
  73.         <thead>
  74.         <tr>
  75.             <th><input type="checkbox" name="select_all" id="select_all" value=""/></th>  
  76.             <th>Student ID</th>      
  77.             <th>User Name</th>
  78.             <th>Status</th>
  79.             <th>Credit</th>
  80.             <th>Time spent on course</th>
  81.         </tr>
  82.         </thead>
  83.         <?php
  84.             if(mysqli_num_rows($query) > 0){
  85.                 while($row = mysqli_fetch_assoc($query)){
  86.         ?>
  87.         <tr>
  88.             <td align="center"><input type="checkbox" name="checked_id[]" class="checkbox" value="<?php echo $row['idscorm_tracking']; ?>"/></td>      
  89.             <td><?php echo $row ['idUser'];?></td>
  90.             <td><?php echo $row['user_name']; ?></td>
  91.             <td><?php echo $row['lesson_status']; ?></td>
  92.             <td><?php echo $row['credit']; ?></td>
  93.             <td><?php echo $row['total_time']; ?></td>
  94.         </tr>
  95.         <?php } }else{ ?>
  96.             <tr><td colspan="5">No records found.</td></tr>
  97.         <?php } ?>
  98.     </table>
  99.     <input type="submit" class="btn btn-danger" name="bulk_update_submit" value="Done"/>
  100. </form>
  101. </body>
  102.  
  103. </html>
  104.  
  105. dbConfig.php:
  106.  
  107. <?php
  108. $dbHost = 'localhost';
  109. $dbUser = 'root';
  110. $dbPass = null;
  111. $dbName = 'remi';
  112. $conn = mysqli_connect($dbHost,$dbUser,$dbPass,$dbName);
  113. if(!$conn){
  114.     die("Database connection failed: " . mysqli_connect_error());
  115. }
  116. ?>
Add Comment
Please, Sign In to add comment