gpt4 book ai didi

php - 为什么我的删除操作没有执行?

转载 作者:行者123 更新时间:2023-11-29 12:15:32 24 4
gpt4 key购买 nike

在我的项目中,当我单击删除按钮时,我希望对特定 ID 执行删除操作,但它没有执行。这是我用于显示表格的代码:

<table class="listing" cellpadding="0" cellspacing="0">
<tr>
<th class="first"><center>Id</center></th>
<th>Category Name</th>
<th>Status</th>
<th>Edit</th>
<th class="last">Delete</th>
</tr>
<?php
include('config.php');
$sql="select * from category_tbl";
$result=mysql_query($sql);
while ($row=mysql_fetch_array($result)) {
if($row['cat_status'] == 0) {
$im='<a href="category.php?false='.$row["cat_id"].'"><img src="../images/red.jpg" height="28" width="28"></a>';
}
else{
$im='<a href="category.php?true='.$row["cat_id"].'"><img src="../images/green.jpg" height="30" width="30"></a>';
}
if (isset($_REQUEST['false'])) {
$updt=mysql_query("update category_tbl set cat_status=1 where cat_id='".$_REQUEST['false']."'");
header('location:category.php');
}
if (isset($_REQUEST['true'])) {
$updt=mysql_query("update category_tbl set cat_status=0 where cat_id='".$_REQUEST['true']."'");
header('location:category.php');
}
?>
<tr>
<td><strong><?php echo $row['cat_id'];?></strong></td>
<td><strong><?php echo $row['cat_name'];?></strong></td>
<td><?php echo $im;?></td>
<td><a href="update_cat.php?id=<?php echo $row['cat_id'];?>"><img src="../images/edit.jpg" height="30" width="60" value=<?php echo $row['cat_id'];?>></a></td>
<td><a href="delete_cat.php?id=<?php echo $row['cat_id'];?>"><img src="../images/delete1.jpg" height="30" width="60" value=<?php echo $row['cat_id'];?>></a></td>
</tr>
<?php
}
?>
</table>

编辑操作有效,但删除操作无效。这是我的删除代码:

<?php
include("config.php");
$id=$_REQUEST['id'];
$sql=mysql_query("DELETE FROM category_tbl WHERE cat_id='".$id."'");
if ($sql) {
header("location:category.php");
}
?>

执行后,它停留在delete_cat.php?id=(passed id)...

最佳答案

我认为您需要从子表中删除外键,或者第二个选项是您需要更改查询并像这样设置级联。

ON DELETE CASCADE

如需更多帮助,请访问此 link

关于php - 为什么我的删除操作没有执行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29864472/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com