我已经定义了三个php文件,首先是function.php,Categories.php和view_all_categories.php
Function.php包含用于删除从category.php传递的变量值中的行的代码。 Category.php在其中包含view_all_categories.php。单击“删除”按钮时,将出现“模式框”,并且在“确认”上,它不会删除相应的行。请帮助
这是Category.php的代码
<?php include"includes/delete_modal.php"; ?>
<div id="wrapper">
<!-- Navigation -->
<?php include"includes/admin_navigation.php"; ?>
<div id="page-wrapper">
<div class="container-fluid">
<div class="row">
<div class="col-xs-6">
<table class="table table-hover table-bordered">
<thead class="thead-dark">
<tr>
<th>Id</th>
<th>Category Title</th>
<th>Options</th>
</tr>
</thead>
<tbody>
<?php //Displasy table from categories
include "includes/view_all_categories.php";?>
<?php //delete categories
delete_categories();
?>
</tbody>
</table>
</div>
</div>
</div>
<!-- /.row -->
</div>
<!-- /.container-fluid -->
</div>
<!-- /#page-wrapper -->
</div>
<!-- /#wrapper -->
<script>
$('#myModal').on('show.bs.modal', function (e) {
$(this).find('.modal_delete_link').attr('href', $(e.relatedTarget).data('href'));
});
</script>
function.php中的类似代码是
function delete_categories(){
global $connection;
if(isset($_GET['delete'])){
$del_id = $_GET['delete'];
$query = "DELETE FROM categories WHERE cat_id = $del_id";
$del_cat = mysqli_query($connection,$query);
$query = "DELETE FROM posts WHERE post_category_id=$del_id";
$del_category_rel_post = mysqli_query($connection,$query);
header("Location: categories.php");
}
和view_all_categories.php文件包括
<?php
$query = "SELECT * FROM categories";
$get_categories = mysqli_query($connection, $query);
while($row = mysqli_fetch_assoc($get_categories)){
$cat_id = $row['cat_id'];
$cat_title = $row['cat_title'];
echo "<tr><td>{$cat_id}</td><td>{$cat_title}</td>
<td><a class='btn btn-danger' data-toggle='modal' data-target='#myModal' data-href='categories.php?delete=$cat_id' href='javascript:void(0)'>Delete</a> <a class='btn btn-primary' href='categories.php?update={$cat_id}'>Update</a></td></tr>";
}
?>
和delete_modal.php具有
<div id="myModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal Content -->
<div class="modal-content">
<div class="modal-container">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Delete Confirm Box</h4>
</div>
<div class="modal-body">
<p> Are you sure you want to delete?</p>
</div>
<div class="modal-footer">
<a class="btn btn-danger modal_delete_link" href="">Delete</a>
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
</div>
</div>
</div>
</div>
</div>
任何帮助都是非常有用的。