php - 如何修复删除按钮无法正常工作?
问题描述
每当我删除要删除的数据时,下一个数据将是要删除的数据。这是我的数据表的代码
示例:我在表中有两个数据(测试 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">×</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 } ?>
解决方案
推荐阅读
- android - 安全存储的限制 - KeyChain 和 KeyStore
- c++ - rcpp和protobuf:Free宏的双重定义
- apache-nifi - 如何使用 NiFi 转换 Jsonfile 的字段?
- java - dataSnapShot.getChildren() 返回 null
- c++ - 为什么哈希模板专业化需要 result_type 和 argument_type?
- c++ - 当我使用 pango 标记时,如何从 MessageDialog 读取变量?
- pandas - Pandas 与两个 DateTime64[ns] 列的差异 - 在午夜时显示“-1 天”
- windows - 使用powershell,如何检查远程服务器帐户的“作为服务登录”?
- javascript - 如何在使用 jquery 1.5.2 重新加载和加载时将 div 放在相同的位置
- c# - MVC 代码优先方法不使用 DbContext 从表中获取数据