diff --git a/create_ticket_api.php b/create_ticket_api.php index 8ca211c..f08b56d 100644 --- a/create_ticket_api.php +++ b/create_ticket_api.php @@ -84,6 +84,22 @@ $conn->query($createTableSQL); $rawInput = file_get_contents('php://input'); $data = json_decode($rawInput, true); +// Validate required fields before any processing +if (!is_array($data) || empty($data['title'])) { + // Try URL-encoded fallback + if (empty($data['title'])) { + parse_str($rawInput, $urlData); + if (!empty($urlData['title'])) { + $data = $urlData; + } + } + if (!is_array($data) || empty($data['title'])) { + http_response_code(400); + echo json_encode(['success' => false, 'error' => 'title is required']); + exit; + } +} + // Generate hash from stable components function generateTicketHash($data) { // Extract device name if present (matches /dev/sdX, /dev/nvmeXnY patterns) @@ -167,11 +183,6 @@ if ($result->num_rows > 0) { // Force JSON content type for all incoming requests header('Content-Type: application/json'); -if (!$data) { - // Try parsing as URL-encoded data - parse_str($rawInput, $data); -} - // Generate ticket ID (9-digit format with leading zeros) $ticket_id = sprintf('%09d', mt_rand(1, 999999999));