Page 1 of 1

Error when linking tickets: "Cannot execute SQL" due to wrong datetime format in dt_created

Posted: Sat Jun 14, 2025 3:30 am
by dmbltda
I encountered a persistent error when trying to link two tickets using the "Link Ticket" feature in HESK. Instead of successfully linking the tickets, the system displayed an error page with the message:
Cannot execute SQL

Cause of the Problem
After some debugging, I found the issue in the SQL INSERT statement in admin_ticket.php, at line 736:

Code: Select all

$q = "INSERT INTO ".hesk_dbEscape($hesk_settings['db_pfix'])."linked_tickets (ticket_id1, ticket_id2, dt_created) VALUES ('".hesk_dbEscape($ticket['id'])."', '".hesk_dbEscape($get_ticket_data['id'])."','".hesk_date()."')"; 
In my installation, the hesk_date() function returns dates in the Brazilian format (d/m/Y H:i:s), for example: 13/06/2025 23:56:59. However, MySQL’s DATETIME field requires the format Y-m-d H:i:s (2025-06-13 23:56:59).

This mismatch caused MySQL to reject the INSERT operation and triggered the error.
Note: In setups where hesk_date() (or the locale) returns dates in American format (Y-m-d H:i:s), this error may not happen, which is why it can go unnoticed in some environments.

Solution
To resolve this, I modified line 736 to use MySQL’s built-in NOW() function for the dt_created column, which always produces a compatible format:

Code: Select all

$q = "INSERT INTO ".hesk_dbEscape($hesk_settings['db_pfix'])."linked_tickets (ticket_id1, ticket_id2, dt_created) VALUES ('".hesk_dbEscape($ticket['id'])."', '".hesk_dbEscape($get_ticket_data['id'])."', NOW())";
After making this change, the tickets were successfully linked and the error no longer occurred.

Summary
  • File: admin_ticket.php
  • Line: 736
  • Problem: Incorrect datetime format for dt_created when linking tickets (Brazilian format: d/m/Y H:i:s)
  • Note: This issue may not occur in environments using the American date format (Y-m-d H:i:s)
  • Solution: Use NOW() in the SQL statement instead of a PHP-formatted date
Hopefully this helps others who encounter the same problem!

Re: Error when linking tickets: "Cannot execute SQL" due to wrong datetime format in dt_created

Posted: Sat Jun 14, 2025 6:35 am
by Klemen
Hi,

Yes, this is indeed a known issue in 3.6.0 and will be addressed in 3.6.1

A patch is already available here:
viewtopic.php?t=7743

Re: Error when linking tickets: "Cannot execute SQL" due to wrong datetime format in dt_created

Posted: Sat Jun 14, 2025 2:11 pm
by dmbltda
Klemen wrote: Sat Jun 14, 2025 6:35 am Hi,

Yes, this is indeed a known issue in 3.6.0 and will be addressed in 3.6.1

A patch is already available here:
viewtopic.php?t=7743
Haaa... nice! Thank you and sorry for a duplicate post about the same issue.

Re: Error when linking tickets: "Cannot execute SQL" due to wrong datetime format in dt_created

Posted: Sat Jun 14, 2025 3:36 pm
by Klemen
No worries, thank you for posting your solution!