arieccomi
sto tentando di eliminare 2 campi sql ho 2 tabelle una si chiama chats e l'altra conversations posto le tabelle tramite un form ho provato con questo codice ma non va
chi può aiutarmi? Grazie
conversasion
chats
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;


conversasion
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
session_start();
#
if(isset($_POST['del'])){
# database connection file
include 'app/db.conn.php';
#
$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;
}
?>
<form action="delchat.php" method="post" enctype="multipart/form-data">
<input type="hidden" value="<?= $_SESSION['name'] ?>">
<input type="submit" name="del" value="Elimina chat">
</form>
Ultima modifica: