33 lines
781 B
PHP
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;
|
|
}
|
|
?>
|