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

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


我在这里尝试了解决方案:从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的代码,具有删除按钮的表单以及该复选框所在的表格。


30秒到达战场
浏览 211回答 1
1回答

慕村225694

让我们将封闭的表单标签放在脚本的末尾,并为您的复选框命名:name =“ checkbox []”<form class="searchBar"&nbsp; &nbsp;method="post" action=''>&nbsp; <input type="submit" action='POST'&nbsp; class="btn-group" id="delete" name="delete" value="delete" style="background-color: #757575; font-family: HelveticaNeue;font-size: 13px;">&nbsp; <table class="taskTable"&nbsp; >&nbsp; &nbsp; <tbody class="task-tbody">&nbsp; &nbsp; &nbsp; &nbsp; <?php while($row1 = mysqli_fetch_array($Table)){ $task123=$row1[2];?>&nbsp; &nbsp; &nbsp; &nbsp; <!-- removed onclick= -->&nbsp; &nbsp; &nbsp; &nbsp; <tr class = "task-tr" onclick="myFunction('<?php echo($task123); ?>')">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <td class="task-td"><input type="checkbox"&nbsp; &nbsp;name="checkbox[]" value="<?php echo $task123?>"/></td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <td class="task-td"> <?php if ($row1[0]=='backlog') {$statuscss= 'statusBacklog';} elseif ($row1[0]== 'inprogress') {$statuscss= 'statusInProgress';} else{ $statuscss= 'statusDone';}&nbsp; &nbsp; echo '<div class="',$statuscss,'">';?><?php echo $row1[0];?></div></td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <td class="task-td"> <?php if ($row1[1]=='HIGH') {$statuscss= 'priorityHigh';} elseif ($row1[1]== 'MEDIUM') {$statuscss= 'priorityMedium ';} else{ $statuscss= 'priorityLow';}&nbsp; &nbsp; echo '<div class="',$statuscss,'">';?>&nbsp; <?php echo $row1[1];?></div></td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <td class="task-td" > <?php echo $task123;?></td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <td class="task-description"> <?php echo $row1[3];?></td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <td class="task-td"> <?php echo $row1[4];?></td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <td class="task-td"> <?php echo $row1[5];?></td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <td class="task-td" width="15"> </td>&nbsp; &nbsp; &nbsp; &nbsp; </tr>&nbsp; &nbsp; &nbsp; &nbsp; <?php }?>&nbsp; &nbsp; </tbody>&nbsp; </table></form>
打开App,查看更多内容
随时随地看视频慕课网APP