34567-vm/employees/delete.php
2025-10-02 20:43:00 +00:00

34 lines
785 B
PHP

<?php
require_once '../db/config.php';
header('Content-Type: application/json');
$id = $_GET['id'] ?? null;
if (!$id) {
http_response_code(400);
echo json_encode(['error' => 'Employee ID is required']);
exit;
}
try {
$pdo = db();
$stmt = $pdo->prepare("SELECT id FROM employees WHERE id = ?");
$stmt->execute([$id]);
if (!$stmt->fetch()) {
http_response_code(404);
echo json_encode(['error' => 'Employee not found']);
exit;
}
$stmt = $pdo->prepare("DELETE FROM employees WHERE id = ?");
$stmt->execute([$id]);
echo json_encode(['success' => 'Employee deleted successfully']);
} catch (PDOException $e) {
http_response_code(500);
echo json_encode(['error' => 'Database error: ' . $e->getMessage()]);
}