- Home
- Categorie
- Coding e Sistemistica
- PHP
- elimina chat utente loggato
-
elimina chat utente loggato
buongiorno sto tentando di eliminare due tabelle ho provato cosi 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; ----------------------------------------------------------- <?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 chat_id AS chats LEFT JOIN conversation_id AS conversations ON chat_id.from_id = conversation_id.conversation_id WHERE chat_id.from_id = 2;'"); $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="<?=$user['username']?>"> <input type="submit" name="del" value="Elimina chat"> </form>