javascript - 使用 PHP POP 删除模式删除操作不起作用?
问题描述
我正在使用 PHP 模式来确认从表中删除记录,但它不起作用。弹出模式即使变成提交也会出现,但不幸的是记录没有被删除。知道为什么无法完成此操作。请为我提供确切的解决方案,我能做些什么来解决问题。
<?php
if(isset($_POST['deletedata']))
{
$id = $_POST['delete_id'];
mysqli_query($db, "DELETE FROM gallery WHERE id=$id");
header("Location:gallery.php");
}
?>
<script>
$(document).ready(function() {
$(".deletebtn").on('click', function() {
$(".deletemodal").modal('show');
var deletedId = $(this).closest("tr").find(':first-child').text();
$("#delete_id").val(deletedId);
});
});
</script>
<!---POP Delete Modal --->
<div class="modal fade" id="deletemodal" class="deletemodal"role="dialog"
aria-hidden="true" ><div class="modal-dialog" >
<div class="modal-content"><div class="modal-header">
<button type="button" class="close"
data-dismiss="modal" aria-hidden="true">×</button>
<h2 class="modal-title">Delete Image</h2>
</div>
<form action="gallery.php" method="post" enctype="multipart/form-
data">
<div class="modal-body">
<input type="hidden" name="delete_id" id="delete_id">
<p>Are you sure you want to delete this image?</p>
</div>
<div class="modal-footer">
<button type="submit" style="margin-right:-5px;"
name="deletedata" class="btn btn-primary" >Yes</button>
<button type="button" style="margin-top:-2px;" class="btn
btn-default " data-dismiss="modal">No</button>
</div>
</form></div></div> </div>
<!---Gallery Table Start --->
<div class="candile">
<div class="candile-inner" style="margin-top:-40px;">
<h3 style="color:#002561">Gallery</h3>
<button type="button" data-toggle="modal" data-target="#gmodal"
class="btn btn-lg btn-default">ADD</button>
<div class="graph">
<div class="tables">
<table class="table table-bordered">
<thead>
<tr>
<th class="th-sm">ID</th>
<th class="th-sm">Title</th>
<th class="th-sm">Content</th>
<th class="th-sm">Image</th>
<th class="th-sm">Edit</th>
<th>Delete</th>
</tr></thead><tbody>
<?php
while($datarecord=mysqli_fetch_assoc($resultrecord))?>
<tr>
<td style="text-align:center;">
<?php echo $datarecord["id"]; ?>
</td>
<td style="text-align:center;">
<?php echo $datarecord["title"]; ?>
</td>
<td>
<?php echo $datarecord["content"]; ?>
</td>
<td style="text-align:center;">
<?php echo '<img src="images/'.$datarecord['gimage'].'">';?></td>
<td style="text-align:center;"><input type="button" data-toggle="modal" data-target="#editegmodal" class="btn btn-lg btn-warning warning_11
editebtn" id="editegbtn" value="Edit"></td>
<td style="text-align:center;"><input type="button" value="Delete" data-toggle="modal" data-target="#deletemodal" class="btn btn-lg btn-
danger deletebtn" id="deletebtn"></td>
</tr>
<?php}?></tbody></table></div></div> </div></div>
解决方案
change edit button with attr id
<input type="button" value="Delete" data-toggle="modal" data-
target="#deletemodal" class="btn btn-lg btn-
danger deletebtn" id="deletebtn" id="<?php echo $datarecord["id"]; ?>">
change button event
var deletedId = $(this).attr("id");
推荐阅读
- json - Chilkat - 从两个数组生成单个 Json 数组
- informatica - Informatica 时间错误,与源数据和目标数据不匹配
- c# - ASP.NET CORE 中有意义的 URL 路由
- java - 使用 ESIG/DSS 将数字签名添加到带有可见时间戳和原因字段的 PDF
- c - 将数字从文件复制到数组时使用 printf 时出现问题
- android - 我有一个 3 列的 Listview,其中包含来自 SQLite DB 的数据和一个 seachview 窗口。我创建了一个自定义数据。搜索未正确执行
- php - curl函数中来自GET的编码url
- css - AngularDart 从包中指定字体
- c# - 使用 Lambda 表达式声明变量和使用 = 运算符有什么区别
- r - 根据日期折叠