如您所见,每条评论都有一个按钮,但是当我单击一个按钮时,它会删除每条评论。我只希望它删除它所属的评论。我可能会明白为什么它会删除所有内容,因为它会comment_id
从$sql_result2
查询中删除列中的所有变量,但我不知道如何修复它。我应该改变我的$sql_result2
吗?我在这里做错了什么?
$sql_result2 = $mysqli2->query("SELECT * FROM comments WHERE thread_id = '".$thread_id."'");
while ($comments = mysqli_fetch_assoc($sql_result2)) {
echo " <div id='comments' >{$comments['comment']}</br>";
echo "<div id='name_and_date'><a href=profile.php?comment_username={$comments['username']}>{$comments['username']}</a></br>";
echo "{$comments['date_made']}</div></div>";
echo <<<EOT
<table style='margin-left:42% ;'>
<form action="?" method="post">
<td><input name="delete_comment" type="submit" value="delete"></td>
<table>
EOT;
if ( isset( $_POST['delete_comment'] ) ) {
$sqldeletecomment=$mysqli2->query("delete from comments WHERE comment_id = '".$comments['comment_id']."'");
header("Location: thread.php");
}
}