prepare("SELECT * FROM files WHERE id = :id"); $stmt->bindParam(':id', $id, PDO::PARAM_INT); $stmt->execute(); $file = $stmt->fetch(PDO::FETCH_ASSOC); if ($file) { // Delete file from server if (file_exists($file['file_path'])) { unlink($file['file_path']); } // Delete record from database $stmt = $db->prepare("DELETE FROM files WHERE id = :id"); $stmt->bindParam(':id', $id, PDO::PARAM_INT); $stmt->execute(); } if ($property_id) { header('Location: edit_property.php?id=' . $property_id . '&message=File deleted successfully'); } elseif ($tenant_id = $_GET['tenant_id'] ?? null) { header('Location: edit_tenant.php?id=' . $tenant_id . '&message=File deleted successfully'); } elseif ($payment_id = $_GET['payment_id'] ?? null) { header('Location: edit_payment.php?id=' . $payment_id . '&message=File deleted successfully'); } else { header('Location: index.php?page=properties&message=File deleted successfully'); } exit; } catch (PDOException $e) { die("DB ERROR: " . $e->getMessage()); } ?>