'Missing household id']); exit; } if (!is_numeric($data['id'])) { http_response_code(400); echo json_encode(['error' => 'id must be numeric']); exit; } $id = (int)$data['id']; $db = getDB(); $checkStmt = $db->prepare('SELECT id FROM households WHERE id = ?'); $checkStmt->execute([$id]); if (!$checkStmt->fetch(PDO::FETCH_ASSOC)) { http_response_code(404); echo json_encode(['error' => 'Household not found']); exit; } $deleteStmt = $db->prepare('DELETE FROM households WHERE id = ?'); $deleteStmt->execute([$id]); echo json_encode([ 'success' => true, 'deleted_id' => $id ]); } catch (Exception $e) { http_response_code(500); echo json_encode(['error' => $e->getMessage()]); } } else { http_response_code(405); echo json_encode(['error' => 'Method not allowed']); } ?>