prepare("SELECT name FROM clients WHERE client_id = ? AND user_id = ?"); $stmt->execute([$clientId, $_SESSION['user_id']]); $client = $stmt->fetch(PDO::FETCH_ASSOC); if (!$client) { // If client not found or doesn't belong to the user, redirect. header('Location: dashboard.php'); exit; } } catch (PDOException $e) { $error = "Error fetching client data: " . $e->getMessage(); } if ($_SERVER['REQUEST_METHOD'] === 'POST') { // Check for confirmation if (isset($_POST['confirm_delete'])) { try { // The ON DELETE CASCADE constraint will handle associated credentials and notes. $stmt = $pdo->prepare("DELETE FROM clients WHERE client_id = ? AND user_id = ?"); $stmt->execute([$clientId, $_SESSION['user_id']]); log_audit_event('client_delete', $_SESSION['user_id'], 'client', $clientId); // Using session to pass success message $_SESSION['success_message'] = "Client '" . htmlspecialchars($client['name']) . "' and all associated data have been deleted."; header('Location: dashboard.php?status=client_deleted'); exit; } catch (PDOException $e) { $error = "Error deleting client: " . $e->getMessage(); } } else { // If not confirmed, just redirect header('Location: dashboard.php?client_id=' . $clientId); exit; } } ?> Delete Client - ClientManager

Delete Client

Are you sure?

This action will permanently delete the client and all of their associated credentials and notes. This cannot be undone.

Cancel
Client not found or you do not have permission to delete it.
Back to Dashboard