File "announcements_delete.php"
Full path: /home2/santhos2/public_html/bharath-coe.firstmatrix.in.net/api/staff_roles/announcements_delete.php
File size: 1.47 KiB (1501 bytes)
MIME-type: text/x-php
Charset: utf-8
<?php
require_once __DIR__ . '/../../config/config.php';
header('Content-Type: application/json');
try {
$announcement_id = (int)($_POST['announcement_id'] ?? $_GET['id'] ?? 0);
if ($announcement_id <= 0) {
echo json_encode(['status' => 'error', 'message' => 'Invalid announcement ID']);
exit;
}
global $pdo;
// Check if table exists
$stmt = $pdo->query("SHOW TABLES LIKE 'result_announcements'");
if ($stmt->rowCount() == 0) {
echo json_encode(['status' => 'error', 'message' => 'Table not found']);
exit;
}
// Check if record exists
$stmt = $pdo->prepare("SELECT announcement_id FROM result_announcements WHERE announcement_id = ?");
$stmt->execute([$announcement_id]);
if ($stmt->rowCount() == 0) {
echo json_encode(['status' => 'error', 'message' => 'Announcement not found']);
exit;
}
// Delete the record
$stmt = $pdo->prepare("DELETE FROM result_announcements WHERE announcement_id = ?");
$stmt->execute([$announcement_id]);
if ($stmt->rowCount() > 0) {
echo json_encode(['status' => 'success', 'message' => 'Announcement deleted successfully']);
} else {
echo json_encode(['status' => 'error', 'message' => 'Failed to delete announcement']);
}
} catch (Exception $e) {
http_response_code(500);
echo json_encode(['status' => 'error', 'message' => $e->getMessage()]);
}
?>