在您的直接链接,你缺少的单引号反转:
echo "<td>" . "<a href='delete.php?del=$row[id]'>Delete</a>" . "</td>";
^-here
应该是这样:
echo "<td>" . "<a href='delete.php?del=$row['id']'>Delete</a>" . "</td>";
而且,在你delete.php,你所得到的值通过POST,而你传递id作为GET,所以使它:
// $con or similar is the variable in your connect.php
include("connect.php");
if(isset($_GET['del']))
{
$id = mysqli_real_escape_string($con, $_GET['del']);
$sql = "DELETE FROM `termekek` WHERE id = $id" ;
echo "<a href='admin.php'>Back</a>";
}
现在,您还需要运行查询。
那么这将工作:
// $con or similar is the variable in your connect.php
include("connect.php");
if(isset($_GET['del']))
{
$id = mysqli_real_escape_string($con, $_GET['id']);
$sql = "DELETE FROM `termekek` WHERE id = $id" ;
mysqli_query($con, $sql);
echo "<a href='admin.php'>Back</a>";
}
此外,小记(听起来很明显):不要GET
方法通过ID或敏感数据。任何人都可以通过仅仅通过将变量del
从url更改为其他id来传递id,那样的事情就会很糟糕。
你不会对你的SQL查询做任何事情。 '$ sql'只是一个字符串,它不会以任何方式操作。 – ConcurrentHashMap
正如@nisbshtr所说,你需要_execute_你的查询。但在此之前,请阅读[documentation](https://dev.mysql.com/doc/refman/4.1/en/delete.html)并修复您的SQL语法 – Clive