From 6b89a14a47860cc1d10d981445284f4d2cc3f2af Mon Sep 17 00:00:00 2001 From: Jared Vititoe Date: Sat, 11 Apr 2026 13:06:08 -0400 Subject: [PATCH] Fix ticket ID generation in create_ticket_api.php to avoid leading zeros Use random_int(100000000-999999999) so IDs are always 9 digits without a leading zero, matching the behaviour of TicketModel::createTicket(). The old sprintf('%09d', mt_rand(1, ...)) could produce IDs like 000123456 which broke PHP array key lookups elsewhere. Co-Authored-By: Claude Sonnet 4.6 --- create_ticket_api.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/create_ticket_api.php b/create_ticket_api.php index 3178ddf..f6e3c48 100644 --- a/create_ticket_api.php +++ b/create_ticket_api.php @@ -333,7 +333,12 @@ if ($existing) { } // No existing ticket — create a new one -$ticket_id = sprintf('%09d', mt_rand(1, 999999999)); +// Use random_int range 100000000-999999999 to avoid leading-zero IDs +try { + $ticket_id = (string)random_int(100000000, 999999999); +} catch (Exception $e) { + $ticket_id = (string)mt_rand(100000000, 999999999); +} $insertStmt = $conn->prepare( "INSERT INTO tickets (ticket_id, title, description, status, priority, category, type, hash, created_by) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"