I have a Dynamic table that has a checkbox on each row. When I click on the check box and then click on my delete button I would like the action to go to my php and delete the row that has a marked checkbox.

I have tried the solution here: Delete selected row from table in php but this did not work for me. I keep getting an error stating that " checkbox is an undefined index"

<?php  
            if (isset($_POST['delete'])){
                $Tasknumber_delete = $_POST['checkbox'];

                mysqli_query($link,"Delete from Universe.Task  where TaskNumber = $Tasknumber_delete");
            }
                ?>


<form class="searchBar"   method="post" action=''>
        <input type="submit" action='POST'  class="btn-group" id="delete" name="delete" value="delete" style="background-color: #757575; font-family: HelveticaNeue;font-size: 13px;">
</form

table class="taskTable"  >
    <tbody class="task-tbody">
        <?php while($row1 = mysqli_fetch_array($Table)){ $task123=$row1[2];?>
        <!-- removed onclick= -->
        <tr class = "task-tr"  onclick="myFunction('<?php echo $task123;?>')">
            <td class="task-td"><input type="checkbox"   name="checkbox" value="<?php echo $task123?>"></td>
            <td class="task-td"> <?php if ($row1[0]=='backlog') {$statuscss= 'statusBacklog';} elseif ($row1[0]== 'inprogress') {$statuscss= 'statusInProgress';} else{ $statuscss= 'statusDone';}    echo '<div class="',$statuscss,'">';?><?php echo $row1[0];?></div></td>
            <td class="task-td"> <?php if ($row1[1]=='HIGH') {$statuscss= 'priorityHigh';} elseif ($row1[1]== 'MEDIUM') {$statuscss= 'priorityMedium ';} else{ $statuscss= 'priorityLow';}    echo '<div class="',$statuscss,'">';?>  <?php echo $row1[1];?></div></td>
            <td class="task-td" > <?php echo $task123;?></td>
            <td class="task-description"> <?php echo $row1[3];?></td>
            <td class="task-td"> <?php echo $row1[4];?></td>
            <td class="task-td"> <?php echo $row1[5];?></td>
            <td class="task-td" width="15"> </td>
        </tr>
        <?php }?>
    </tbody>
</table>

I added the code for the delete php, the form that has the delete button and my table where the check box is located.

1 Answers

2
sylvain On Best Solutions

Let's put the closed form-tag at the end of your script and name your checkbox : name="checkbox[]"

<form class="searchBar"   method="post" action=''>
  <input type="submit" action='POST'  class="btn-group" id="delete" name="delete" value="delete" style="background-color: #757575; font-family: HelveticaNeue;font-size: 13px;">

  <table class="taskTable"  >
    <tbody class="task-tbody">
        <?php while($row1 = mysqli_fetch_array($Table)){ $task123=$row1[2];?>
        <!-- removed onclick= -->
        <tr class = "task-tr" onclick="myFunction('<?php echo($task123); ?>')">
            <td class="task-td"><input type="checkbox"   name="checkbox[]" value="<?php echo $task123?>"/></td>
            <td class="task-td"> <?php if ($row1[0]=='backlog') {$statuscss= 'statusBacklog';} elseif ($row1[0]== 'inprogress') {$statuscss= 'statusInProgress';} else{ $statuscss= 'statusDone';}    echo '<div class="',$statuscss,'">';?><?php echo $row1[0];?></div></td>
            <td class="task-td"> <?php if ($row1[1]=='HIGH') {$statuscss= 'priorityHigh';} elseif ($row1[1]== 'MEDIUM') {$statuscss= 'priorityMedium ';} else{ $statuscss= 'priorityLow';}    echo '<div class="',$statuscss,'">';?>  <?php echo $row1[1];?></div></td>
            <td class="task-td" > <?php echo $task123;?></td>
            <td class="task-description"> <?php echo $row1[3];?></td>
            <td class="task-td"> <?php echo $row1[4];?></td>
            <td class="task-td"> <?php echo $row1[5];?></td>
            <td class="task-td" width="15"> </td>
        </tr>
        <?php }?>
    </tbody>
  </table>

</form>