<div class="comments__container">
<div class="comments__body">
<?php
$comments = [];
$query = $conn->query("SELECT * FROM `comments`");
$comments = $query->fetchAll(PDO::FETCH_ASSOC);
foreach($comments as $comment){
?>
<div class="comments__item">
<div class="comments__people">
<div class="comments__name"><?= $comment['name']?></div>
</div>
<?php
if($comment['user_id'] == $_COOKIE['user_id']){
?>
<div class="comments__control">
<a href="php/change_comment.php" class="comments__change">Изменить</a>
<a href="php/delete_comment.php" class="comments__delete">Удалить</a>
</div>
<?php
}
?>
<div class="comments__message"><?= $comment['message']?></div>
</div>
<?php
}
?>
</div>
</div>
<?php
require 'config.php';
$user_id = $_COOKIE['user_id'];
$delete = $conn->prepare("DELETE FROM `comments` WHERE `user_id` = :user_id");
$delete->execute(['user_id' => $user_id]);
header('Location: ../index.php');
?>
DELETE FROM `comments`
WHERE `user_id` = :user_id
and `id` = :comment_id