Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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?
- action.php:
- <?php
- session_start();
- include_once('dbConfig.php');
- if(isset($_POST['bulk_UPDATE_submit'])){
- $idArr = $_POST['checked_id'];
- foreach($idArr as $id){
- mysqli_query($conn,"UPDATE learning_scorm_tracking SET lesson_status = 'incomplete' WHERE idscorm_tracking=".$id);
- }
- $_SESSION['success_msg'] = 'Users have been UPDATED successfully.';
- header("Location:index.php");
- }
- ?>
- index.php:
- <!DOCTYPE html>
- <html>
- <head>
- <title>Delete multiple rows in PHP by CodexWorld</title>
- <link rel="stylesheet" href="style.css"/>
- <script type="text/javascript" src="jquery.min.js"></script>
- <script type="text/javascript">
- function update_confirm(){
- var result = confirm("Are you sure to update student?");
- if(result){
- return true;
- }else{
- return false;
- }
- }
- $(document).ready(function(){
- $('#select_all').on('click',function(){
- if(this.checked){
- $('.checkbox').each(function(){
- this.checked = true;
- });
- }else{
- $('.checkbox').each(function(){
- this.checked = false;
- });
- }
- });
- $('.checkbox').on('click',function(){
- if($('.checkbox:checked').length == $('.checkbox').length){
- $('#select_all').prop('checked',true);
- }else{
- $('#select_all').prop('checked',false);
- }
- });
- });
- </script>
- </head>
- <body>
- <?php session_start(); if(!empty($_SESSION['success_msg'])){ ?>
- <div class="alert alert-success"><?php echo $_SESSION['success_msg']; ?></div>
- <?php unset($_SESSION['success_msg']); } ?>
- <?php
- include_once('dbConfig.php');
- $query = mysqli_query($conn,"SELECT * FROM learning_scorm_tracking WHERE lesson_status = 'completed'");
- ?>
- <form name="bulk_action_form" action="action.php" method="post" onSubmit="return update_confirm();"/>
- <table class="bordered">
- <thead>
- <tr>
- <th><input type="checkbox" name="select_all" id="select_all" value=""/></th>
- <th>Student ID</th>
- <th>User Name</th>
- <th>Status</th>
- <th>Credit</th>
- <th>Time spent on course</th>
- </tr>
- </thead>
- <?php
- if(mysqli_num_rows($query) > 0){
- while($row = mysqli_fetch_assoc($query)){
- ?>
- <tr>
- <td align="center"><input type="checkbox" name="checked_id[]" class="checkbox" value="<?php echo $row['idscorm_tracking']; ?>"/></td>
- <td><?php echo $row ['idUser'];?></td>
- <td><?php echo $row['user_name']; ?></td>
- <td><?php echo $row['lesson_status']; ?></td>
- <td><?php echo $row['credit']; ?></td>
- <td><?php echo $row['total_time']; ?></td>
- </tr>
- <?php } }else{ ?>
- <tr><td colspan="5">No records found.</td></tr>
- <?php } ?>
- </table>
- <input type="submit" class="btn btn-danger" name="bulk_update_submit" value="Done"/>
- </form>
- </body>
- </html>
- dbConfig.php:
- <?php
- $dbHost = 'localhost';
- $dbUser = 'root';
- $dbPass = null;
- $dbName = 'remi';
- $conn = mysqli_connect($dbHost,$dbUser,$dbPass,$dbName);
- if(!$conn){
- die("Database connection failed: " . mysqli_connect_error());
- }
- ?>
Add Comment
Please, Sign In to add comment