我正在尝试将删除链接添加到页面上显示的每一行记录。到目前为止,我已经做到了这一点,但无法弄清楚如何使链接工作,以便在单击删除链接时,只会从数据库中删除该行数据。我对 php/mysql 还很陌生,所以请原谅我的问题。到目前为止,我有以下代码..
<?php
require("common.php");
if(empty($_SESSION['user']))
{
header("Location: index.php");
die("Redirecting to index.php");
}
$result = $db->prepare("SELECT * FROM compliance_requirement");
$result->execute();
?>
<div class="compTable">
<table >
<tr>
<th>Compliance Name</th><th>Compliance Goal</th><th>Compliance Description</th> <th>Options</th>
</tr>
<?php while($row = $result->fetch(PDO::FETCH_ASSOC)){ ?>
<tr>
<td style='width: 200px;'><?php echo $row['ComplianceName']; ?></td>
<td style='width: 150px;'><?php echo $row['ComplianceGoal']; ?></td>
<td style='width: 400px;'><?php echo $row['ComplianceDescription']; ?></td>
<td style ='width: 250px;' ><?php echo '<a href="delete.php?action=delete&id=delete'.$row['ComplianceName'].'">Delete</a>';?>
</td>
</tr>
<?php }
?>
</table>
</div>
.. 然后在我的 delete.php 文件中,我有以下代码:
<?php
require ('common.php');
if( isset($_GET['delete']) )
{
$id = $_GET['delete'];
$sql= $db->prepare("DELETE FROM compliance_requirement WHERE ComplianceName='$id'");
$sql->execute();
echo "<meta http-equiv='refresh' content='0;url=compliance.php'>";
}
?>
单击删除链接时,它只会出现一个空白屏幕。任何帮助深表感谢!谢谢