删除链接不删除mysql数据库中的任何记录 [英] delete link not deleting any record in mysql database

查看:65
本文介绍了删除链接不删除mysql数据库中的任何记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试向页面上显示的每一行记录添加一个删除链接.到目前为止,我已经设法解决了这一问题,但无法弄清楚如何使链接正常工作,因此,当单击删除链接时,只会从数据库中删除该行数据.我是php/mysql的新手,请原谅我的问题.到目前为止,我有以下代码.

I am trying to add a delete link to every row of record displayed on my page. I have managed to that so far but cannot figure out how to make the link work so that when a delete link is clicked, only that row of data will be removed from the database. I am farly new to php/mysql so pardon my questions. I have the following code so far..

<?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文件中,我有以下代码:

.. and then in my delete.php file, I have the following code:

<?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'>";
}
?>

单击删除链接后,它只会显示一个空白屏幕.任何帮助深表感谢!谢谢

When the delete link is clicked, it just comes up with a blank screen. Any help is much appreciated! Thanks

推荐答案

您的 a href 标签应为[缺少引号]

<?php echo '<a href="delete.php?action=delete&id='.$row['ComplianceName'].'">Delete</a>';?>  
<?php echo '<a href="delete.php?edit='.$row['ComplianceID'].'">Edit</a>';?> 
<?php echo '<a href="delete.php?invite='.$row['id'].'">Invite Obstacle</a>';?> 

这篇关于删除链接不删除mysql数据库中的任何记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆