eliminazione stanza creata da admin

  • Creatore Discussione Creatore Discussione Imperor
  • Data di inizio Data di inizio

Imperor

Utente Attivo
25 Nov 2010
102
2
18
Roma
www.fcfclean.it
salve non riesco a impostare per eliminare la stanza creata da admin e i messaggi quando un utente crea la stanza diventa admin posto le foto delle tabelle
Screenshot (136).png
Screenshot (137).png
Screenshot (138).png

Codice:
<?php
session_start();
// Include the database connection file
require 'db.php';
require 'admin.php';
if ($_SESSION['role'] != 'admin') {
echo 'Access denied';
exit;
}



if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $id = $_SESSION['user_id'];
    $id = $_POST['id'];
   
       

    // Begin transaction
    $pdo->beginTransaction();

    try {
        // Delete messages related to the chatroom
        $stmt = $pdo->prepare('DELETE FROM messages WHERE  id = (SELECT * FROM chatrooms WHERE created_by = :id)');
        $stmt->execute(['id' => $id]);

        // Delete the chatroom
        $stmt = $pdo->prepare('DELETE FROM chatrooms WHERE id = :id');
        $stmt->execute(['id' => $id]);
       
        $stmt = $pdo->prepare('DELETE FROM user_roles WHERE  id = :user_id');
        $stmt->execute(['id' => $user_id]);

        // Commit the transaction
        $pdo->commit();

        echo "Chatroom and related messages deleted successfully.";
    } catch (Exception $e) {
        // Rollback the transaction if something went wrong
        $pdo->rollBack();
        echo "Failed to delete chatroom: " . $e->getMessage();
    }
}
?>
 
Ultima modifica:

Discussioni simili