如何修复删除按钮无法正常工作?

无论何时何地删除我想要删除的数据,它会发生什么是下一个数据,它将是将被删除的数据。这是我的数据表的代码

Example:我在表中有两个数据(测试1,test2)如果我删除数据“test 1”,则test2是一直删除的。

删除已插入数据库中的最新数据。

> <?php  
>                $count = 0;
>                   while($row = mysqli_fetch_array($result))  
>                 {  
>                     $count = $count + 1;
>                 ?>  
>                        <tr> 
>                          <td style="display: none;"><?php echo $row["id"]; ?></td>
>                          <td><?php echo $row["name"]; ?></td>
>                          <td><?php echo $row["message"]; ?></td>
>                          <td><?php echo $row["date_post"]; ?></td>
>                                             
>                          <td><input type="button"class="btn btn-danger btn-sm delete_data" value="Delete" data-toggle="modal"
> data-target="#DeleteModalLong"></input></td> 
>          
>         
>                         <div class="modal fade" id="DeleteModalLong" tabindex="-1" role="dialog" aria- 
>                          labelledby="DeleteModalLongTitle" aria-hidden="true">
>                                             <div class="modal-dialog modal-xl" role="document">
>                                               <div class="modal-content">
>                                                 <div class="modal-header">
>                                      <h5 class="modal-title" id="DeleteModalLongTitle">Confirm Action</h5>
>                               <button type="button" class="close" data-dismiss="modal" aria-label="Close">
>                                 <span aria-hidden="true">&times;</span></button>
>                                               </div>
>         
>                                               <div class="modal-body">
>                                                 Are you sure you want to delete this?
>                                               </div>
>          <div class="modal-footer">
>         
>         <a href="delete_announcement.php?id=<?php echo $row["id"]; ?>" type="submit" class="btn btn-danger" value="Yes"
> name="delete_announce" id="delete_announce">Yes</a>
>         <input type="button" value="No" class="btn btn-primary btn-md" data-dismiss="modal"> 
>                                               </div>
>                                             </div></div></div>
>              
>                                        </tr>  
>         
>                                        <?php  
>                                        } 
>         
>                                        ?>  
>                                        </tbody>
>     
>     //and here's the code for delete_announcement.php
>     
>     
>     
>     > <?php include "db_announce.php"; // Using database connection file
>     > here
>     > 
>     > $id = $_GET['id']; // get id through query string
>     > 
>     > $del = mysqli_query($con,"delete from tbl_announce where id =
>     > '".$id."'"); // delete query
>     > 
>     > if($del) {
>     >     mysqli_close($con); // Close connection
>     >     header("location:dashboard.php"); // redirects to all records page
>     >     $_SESSION['message'] = "Success! Data has been deleted";
>     >     $_SESSION['msg_type'] = "success";
>     >      header("location: dashboard.php");
>     >     exit;    } else {
>     >     echo "Error deleting record"; // display error message if not delete } ?>
请勿格式化整个代码块.CBROE
ID在HTML文档中必须是唯一的,并且通过在循环中创建此内容,您将违反多个位置。CBROE

回答 0