I made messaging system for my site and this is the code I use to display the different users messages in their profile. This gets the messages from the database and displays them in the page in divs (every message in new div). I added 'DELETE MESSAGE' to user to delete the certain message but I don't know how it will work. I want it to delete the div and the database record. I am new in PHP and it is super complicated for me to make it.
<div style='height: auto; margin-top: 0px; padding: 50px;' id='content'>
<?php
session_start();
if (!isset($_SESSION['name'])) {
header('Location:vhod.php');
exit;
}
$pageTitle = 'СЪОБЩЕНИЯ';
include 'includes/header.html';
$email = $_SESSION['email'];
$name = $_SESSION['name'];
include 'php/db_connect.php';
$msgs = '';
$query = "SELECT * FROM `msg` WHERE `to` = '$name'";
$result = mysqli_query($conn, $query);
if (mysqli_num_rows($result) > 0) {
while($row = mysqli_fetch_assoc($result)) {
echo "<div class='msg_box'>" . "<strong>>> Дата и час: </strong>" . $row["timestamp"] . "<br>" . " <strong>>> От: </strong>" . "<i>" . $row["sender"] . "</i>" . "<br>" . " <strong>>> Тема: </strong>" . "<i>" . $row["subject"] . "</i>" . "<br>" . "<strong>>> Съобщение: </strong>" . "<i>" . $row["msg"] . "</i>" . "<br>" ."<br>" ."<strong><a href='' >DELETE MESSAGE</a></strong>" . "</div>" . "<br>" . "<br>" . "<br>" ;
}
} else {
echo "<h2>Нямате съобщения :(</h2>";
}
?>
</div>