由于树使用的SQL查询中的变量,JS Tree无法获取正确的数据

I am new to the platform and i'm not familiar with how i should describe better for everyone this problem but i hope that i will make it clear. I am tryng to make a website wich includes a page with a "tree". This "tree" form will include boxes, folders and files. The tree is based on the "id" and "parent id" principle. I have also a input where i take a 21 characters string and search by that string in the database. Unfortunely it is not working with the variable, is working just if i place a value in the query or a variable allready declared with the value.

I compared the value already declared with the one taken from the input and they are the same I tried to encode the variable in utf8

The query from fetch.php that doesn't load

$pr=$_GET['code'];
$pr2=utf8_encode_deep($pr);

     $sql=";with cte 
            as (select code128 as id,below as parent_id,comment as name, comment as text
            from hrdocs as h 
            where code128 = '$pr2'
            UNION ALL
            select h.code128, h.below, h.comment, h.comment
            from hrdocs as h 
            join cte 
            on h.below = cte.id)
            select *
            from cte
            order by parent_id asc;";

The query from fetch.php that works


$pr2='170720190945070507790';

     $sql=";with cte 
            as (select code128 as id,below as parent_id,comment as name, comment as text
            from hrdocs as h 
            where code128 = '$pr2'
            UNION ALL
            select h.code128, h.below, h.comment, h.comment
            from hrdocs as h 
            join cte 
            on h.below = cte.id)
            select *
            from cte
            order by parent_id asc;";

I want to be able to use that variable from input in order to have a tree just from the master type of box/folder/file that i am searching for.