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

Helpdesk for my helpdesk software

Moderator: mkoch227

Post Reply
dmbltda
Posts: 2
Joined: Sat Jun 14, 2025 3:16 am

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

Post 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!
Klemen
Site Admin
Posts: 10139
Joined: Fri Feb 11, 2005 4:04 pm

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

Post 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
Klemen, creator of HESK and PHPJunkyardWas this helpful? You can buy me a drink here Image

Image You should follow me on Twitter here

Help desk software | Cloud help desk | Guestbook | Link manager | Click counter | more PHP Scripts ...

Also browse for php hosting companies, read php books, find php resources and use webmaster tools
dmbltda
Posts: 2
Joined: Sat Jun 14, 2025 3:16 am

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

Post 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.
Klemen
Site Admin
Posts: 10139
Joined: Fri Feb 11, 2005 4:04 pm

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

Post by Klemen »

No worries, thank you for posting your solution!
Klemen, creator of HESK and PHPJunkyardWas this helpful? You can buy me a drink here Image

Image You should follow me on Twitter here

Help desk software | Cloud help desk | Guestbook | Link manager | Click counter | more PHP Scripts ...

Also browse for php hosting companies, read php books, find php resources and use webmaster tools
Post Reply