Error Found in 3.6.0

Helpdesk for my helpdesk software

Moderator: mkoch227

Post Reply
shddcit
Posts: 60
Joined: Wed Mar 30, 2022 3:54 pm

Error Found in 3.6.0

Post by shddcit »

Good day, Klemen.

Another error has been found in version 3.6.0.

Action: Adding a note to a ticket
Result: SQL Execution Error

Response with debugging enabled:
Could not execute SQL:
SELECT COUNT(*) FROM hesk_users WHERE (id='14' AND notify_note='1') OR (notify_collaborator_note='1' AND id IN ())
MySQL response:
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '))' at line 1.
The issue is due to an empty IN () condition at the end — it's invalid to use an empty list inside an IN clause. This occurs when the ticket has no collaborator users assigned.

Proposed Fix (worked for me):

In the file admin_ticket.php, locate this section (around line 508):

Code: Select all

$res = hesk_dbQuery("SELECT COUNT(*) FROM `".hesk_dbEscape($hesk_settings['db_pfix'])."users` WHERE (`id`='".intval($ticket['owner'])."' AND `notify_note`='1') OR (`notify_collaborator_note`='1' AND `id` IN (".implode(",", $ticket['collaborators'])."))");
Modify it to first check whether there are any collaborators:

Code: Select all

$collaborators_sql = count($ticket['collaborators']) ? "(`notify_collaborator_note`='1' AND `id` IN (".implode(",", $ticket['collaborators'])."))" : "0";
$res = hesk_dbQuery("SELECT COUNT(*) FROM `".hesk_dbEscape($hesk_settings['db_pfix'])."users` WHERE (`id`='".intval($ticket['owner'])."' AND `notify_note`='1') OR ".$collaborators_sql);
This change will:
  • First check if there are any collaborators.
  • If there are, include them in the query using the IN clause.
  • If there are no collaborators, replace that part of the condition with "0" (false), which effectively skips it.
The fixed query avoids the empty IN () syntax error while preserving the intended functionality.

You might also want to consider adding additional error checking to ensure that $ticket['collaborators'] is always an array (even if empty), to prevent potential issues elsewhere in the code.
Klemen
Site Admin
Posts: 10139
Joined: Fri Feb 11, 2005 4:04 pm

Re: Error Found in 3.6.0

Post by Klemen »

Yes, it is indeed an error in 3.6.0

We have already fixed it for 3.6.1, but haven't released it yet. Thanks for sharing your solution here.
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