首页 > 解决方案 > 如何修复删除按钮无法正常工作?

问题描述

每当我删除要删除的数据时,下一个数据将是要删除的数据。这是我的数据表的代码

示例:我在表中有两个数据(测试 1,测试 2)如果我删除数据“测试 1”,则测试 2 是正在删除的数据。

它正在删除已插入数据库的最新数据。

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

标签: phpmysqlfunctionmodal-dialog

解决方案


推荐阅读