36952-vm/delete_tenant.php
Flatlogic Bot 76d7d99142 PMS 1
2025-12-15 01:31:18 +00:00

33 lines
781 B
PHP

<?php
require_once 'session.php';
check_admin();
require_once 'db/config.php';
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
header('Location: index.php?tab=tenants');
exit;
}
$id = $_POST['id'] ?? 0;
if (!$id) {
header('Location: index.php?tab=tenants&error=InvalidID');
exit;
}
try {
$db = db();
$stmt = $db->prepare("DELETE FROM tenants WHERE id = :id");
$stmt->bindParam(':id', $id, PDO::PARAM_INT);
$stmt->execute();
if ($stmt->rowCount() > 0) {
header('Location: index.php?tab=tenants&status=deleted');
} else {
header('Location: index.php?tab=tenants&error=NotFound');
}
exit;
} catch (PDOException $e) {
header('Location: index.php?tab=tenants&error=' . urlencode($e->getMessage()));
exit;
}
?>