gpt4 book ai didi

php - 删除按钮在表格行中不起作用

转载 作者:行者123 更新时间:2023-11-29 19:03:34 24 4
gpt4 key购买 nike

我试图在每一行添加一个删除按钮,以便按下按钮时可以删除记录。但删除功能不起作用并显示“删除记录时出错”。不知道问题出在哪里。

请帮助我。任何帮助将不胜感激。

这是我的代码:

ma​​nagetimetable.php

<?php 
include("include/config.php");

$sql = "SELECT * FROM `time_table`";
$query = mysqli_query($link,$sql) or die(mysqli_error($link));
?>

<table width="70%" cellpadding="5" cellspacing="5">
<tr>
<th><strong>ID</strong></th>
<th><strong>Image</strong></th>
<th></th>
</tr>

<?php while ($row = mysqli_fetch_array($query)) : ?>
<tr>
<td><?php echo $row['t_id']; ?></td>
<td><?php echo $row['t_name']; ?></td>
<td><a href='delete.php?id=".$row['t_id']."'>Delete</a></td>
</tr>
<?php endwhile; ?>
</table>

删除.php

<?php
$id = $_GET['id'];

include("include/config.php");

$sql = "DELETE FROM time_table WHERE t_id = $id";

if (mysqli_query($link, $sql)) {
mysqli_close($link);
header('Location: index.php');
exit;
} else {
echo "Error deleting record";
}
?>

config.php

<?php $link=mysqli_connect("localhost","root","","course_registration_system"); ?>

我的数据库:时间表

t_id  t_name                    t_image 
8 course_offered_2017.jpg [BLOB - 246.1 KiB]
9 time_table_2017.jpg [BLOB - 446.4 KiB]

最佳答案

替换这个

   <td><a href='delete.php?id=".$row['t_id']."'>Delete</a></td>

   <td><a href='delete.php?id=<?php echo $row["t_id"];?>'>Delete</a></td>

*尝试使用pdo

关于php - 删除按钮在表格行中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43683297/

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