在您的直接鏈接,你缺少的單引號反轉:
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