salve scusate la risposta in ritardo ho risolto usando tipo file manager :) ma ora ho un altro problema devo eliminare due campi ho 2 tabelle con una si chiama chats e l'altra conversations ho creato un form e un file delchat.php questo è ciò che ho fatto ma non va :(
------------------------
CREATE TABLE `chats` (
`chat_id` int(11) NOT NULL,
`from_id` int(11) NOT NULL,
`to_id` int(11) NOT NULL,
`message` text NOT NULL,
`opened` tinyint(1) NOT NULL DEFAULT 0,
`created_at` datetime NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
-- --------------------------------------------------------
--
-- Table structure for table `conversations`
--
CREATE TABLE `conversations` (
`conversation_id` int(11) NOT NULL,
`user_1` int(11) NOT NULL,
`user_2` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
Codice PHP:
<ul id="chatList"
class="list-group mvh-50 overflow-auto">
<?php if (!empty($conversations)) { ?>
<?php
foreach ($conversations as $conversation){ ?>
<li class="list-group-item">
<p>Elimina chat</p>
<form action="delchat.php" method="post" enctype="multipart/form-data">
<input type="hidden" value="<?=$user['username']?>">
<input type="submit" name="del" value="Elimina chat">
</form>
<a href="chat.php?user=<?=$conversation['username']?>"
class="d-flex
justify-content-between
align-items-center p-2">
<div class="d-flex
align-items-center">
<img src="uploads/<?=$conversation['p_p']?>"
class="w-10 rounded-circle">
<h3 class="fs-xs m-2">
<?=$conversation['username']?><br>
<?=$conversation['name']?><br>
<small>
<?php
echo lastChat($_SESSION['user_id'], $conversation['user_id'], $conn);
?>
</small>
--------------------------------------
delchat.php
<?php
session_start();
# check if the user is logged in
if(isset($_POST['del'])){
# database connection file
include 'app/db.conn.php';
# get the logged in user's username from SESSION
$user_id = $_SESSION['user_id'];
$chat_id = $_POST['chat_id'];
$conversation_id = $_POST['conversation_id'];
$sql = "DELETE chats,conversations FROM chats
INNER JOIN
conversation_id ON conversations.ref = chats.chat_id
WHERE
chats.chat_id = 1;'");
$stmt= $conn->prepare($sql);
$stmt->execute([$chat_id, $conversation_id]);
header("Location: home.php");
exit;
}
?>