我對我的index.php頁面有一個評論部分。 (就像我在這裏顯示的那樣)我有一個刪除鏈接,將您發送到刪除頁面。我希望能夠在單擊時刪除該特定ID。 的index.php從Mysqli中刪除選定的ID
<div class='commentnest'>
<p id='id'> ".$row['id']."</p>
<p id='user'> ".$row['user'].":</p>
<p id='comment'>".$row['usercomment']." </p>
<p id='time'>".$row['timestamp']."</p>
<a href='delete.php?=".$row['id']."'>Delete</a>
</div>
delete.php頁
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "DELETE FROM commenttable WHERE id=id";
if (mysqli_query($conn, $sql)) {
echo "Record deleted successfully";
} else {
echo "Error deleting record: " . mysqli_error($conn);
}
mysqli_close($conn);
?>
每次我發送一個特定的評論有時間
,它會刪除所有的意見。我知道這是因爲我沒有說明要選擇哪個ID,但我很難搞清楚。
感謝您的幫助!
閱讀 - http://php.net/manual/en/tutorial.forms.php – splash58
'id = id'爲true。 http://sqlfiddle.com/#!9/add33/3首先命名您的'GET'參數。然後使用參數化查詢刪除該值。 – chris85
您需要一個GET數組用於此 –