From c442e2d47f2bc8441f3d936368c2c80dd0cd6d8a Mon Sep 17 00:00:00 2001 From: Jared Vititoe Date: Sat, 11 Apr 2026 13:40:15 -0400 Subject: [PATCH] Fix AttachmentModel ticket_id binding to preserve leading zeros All ticket_id parameters were bound as integer ("i"), which stripped leading zeros before insertion into ticket_attachments.ticket_id (VARCHAR 9). This caused a mismatch: upload_attachment.php creates the directory using the full string (e.g. /uploads/000123456/) but the DB stored the integer form ("123456"), so download and delete would look in the wrong path. Changed getAttachments, addAttachment, getTotalSizeForTicket, and getAttachmentCount to use string binding ("s") so the canonical zero-padded ticket ID is stored and read back consistently. Co-Authored-By: Claude Sonnet 4.6 --- models/AttachmentModel.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/models/AttachmentModel.php b/models/AttachmentModel.php index c5d6ac4..0ae5783 100644 --- a/models/AttachmentModel.php +++ b/models/AttachmentModel.php @@ -21,7 +21,7 @@ class AttachmentModel { ORDER BY a.uploaded_at DESC"; $stmt = $this->conn->prepare($sql); - $stmt->bind_param("i", $ticketId); + $stmt->bind_param("s", $ticketId); $stmt->execute(); $result = $stmt->get_result(); @@ -61,7 +61,7 @@ class AttachmentModel { VALUES (?, ?, ?, ?, ?, ?)"; $stmt = $this->conn->prepare($sql); - $stmt->bind_param("issisi", $ticketId, $filename, $originalFilename, $fileSize, $mimeType, $uploadedBy); + $stmt->bind_param("sssisi", $ticketId, $filename, $originalFilename, $fileSize, $mimeType, $uploadedBy); $result = $stmt->execute(); if ($result) { @@ -97,7 +97,7 @@ class AttachmentModel { WHERE ticket_id = ?"; $stmt = $this->conn->prepare($sql); - $stmt->bind_param("i", $ticketId); + $stmt->bind_param("s", $ticketId); $stmt->execute(); $result = $stmt->get_result(); $row = $result->fetch_assoc(); @@ -113,7 +113,7 @@ class AttachmentModel { $sql = "SELECT COUNT(*) as count FROM ticket_attachments WHERE ticket_id = ?"; $stmt = $this->conn->prepare($sql); - $stmt->bind_param("i", $ticketId); + $stmt->bind_param("s", $ticketId); $stmt->execute(); $result = $stmt->get_result(); $row = $result->fetch_assoc();