我正在尝试使用复选框删除一行数据,当我单击删除时,我的php应该删除该行

时间:2019-04-13 20:39:13

标签: javascript php

我有一个动态表,每行都有一个复选框。当我单击复选框,然后单击删除按钮时,我希望操作转到我的PHP并删除具有标记复选框的行。

我在这里尝试了解决方法:Delete selected row from table in php,但这对我不起作用。我不断收到错误消息,指出“复选框是未定义的索引”

<?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>

我添加了删除php的代码,具有删除按钮的表单以及复选框所在的表格。

1 个答案:

答案 0 :(得分:2)

让我们将封闭的表单标签放在脚本的末尾,然后将您的复选框命名为: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>