[英]query that should delete records doesnt work (php)
I've been trying to delete a record in HTML/PHP but it didn't work and I've tried a lot. 我一直在尝试删除HTML / PHP中的记录,但是它没有用,我已经做了很多尝试。 Does anyone know a solution for me? 有人知道我的解决方案吗?
<?php while($row=mysqli_fetch_assoc($result)){ ?>
<a href="delete.php?id=<?php echo $row['project_id']; ?>Delete</a>
<?php
}?>
And this is delete.php: 这是delete.php:
<?php
$id = $_GET['titel'];
$sql = "DELETE FROM Projects where titel= '".$id."'";
if(mysqli_query($dbLink,$sql)){
echo "<p>It is failed!</p>";
}
else{
echo "<p>Deleting is succesful done!</p>";}
?>
Please find below the updated code. 请在下面找到更新的代码。 Kindly use delete on particular row id as title or any other field may create some issue. 请在特定的行ID上使用delete作为标题,否则任何其他字段都可能造成问题。
<a href="delete.php?project_id=<?php echo $row['project_id']; ?>Delete</a>
<?php
}?>
And this is delete.php: 这是delete.php:
<?php
$id = $_GET['project_id'];
$sql = "DELETE FROM Projects where project_id= '".$id."'";
if(mysqli_query($dbLink,$sql)){
echo "<p>It is failed!</p>";
}
else{
echo "<p>Deleting is succesful done!</p>";}
?>
You're trying to $_GET['titel'];
您正在尝试$_GET['titel'];
but what you're meant to get is $_GET['id'];
但是您打算得到的是$_GET['id'];
Either change it to id
, or change your a
link to: 无论是将其更改为id
,或者改变你a
链接:
<a href="delete.php?titel=<?php echo $row['project_id']; ?>Delete</a>
What you should do then, in your delete.php
file, is change your $sql
to: 然后,在delete.php
文件中,应该将$sql
更改为:
$sql = "DELETE FROM Projects where id= '".$id."'";
Also ensure $dbLink
is set in delete.php
. 还要确保在delete.php
设置了$dbLink
。
Your $_GET will not work as you are sending id
in your query string. 您的$ _GET将不起作用,因为您要在查询字符串中发送id
。 Try the following in delete.php
在delete.php
尝试以下delete.php
$id = $_GET['id'];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.