What is the solution for this error message??

I write this as my query.

$query="SELECT distinct e.* from entities e JOIN objects_entity o on e.guid = o.guid JOIN (SELECT subm1.*, s1.string FROM metadata subm1 JOIN metastrings s1 ON subm1.value_id = s1.id) AS m1 ON e.guid = m1.entity_guid JOIN (SELECT subm2.*, s2.string FROM metadata subm2 JOIN metastrings s2 ON subm2.value_id = s2.id) AS m2 ON e.guid = m2.entity_guid JOIN (SELECT subm3.*, s3.string FROM metadata subm3 JOIN metastrings s3 ON subm3.value_id = s3.id) AS m3 ON e.guid = m3.entity_guid JOIN (SELECT subm4.*, s4.string FROM metadata subm4 JOIN metastrings s4 ON subm4.value_id = s4.id) AS m4 ON e.guid = m4.entity_guid where ((m1.name_id='298' AND m1.string IN (". $filter.")) and (m4.name_id='318' AND m4.string >= ".$dd.")) and e.subtype= '12' and ( (1 = 1) and e.enabled='yes') and ( (1 = 1) and m1.enabled='yes') and ( (1 = 1) and m2.enabled='yes') and ( (1 = 1) and m3.enabled='yes') and ( (1 = 1) and m4.enabled='yes') and e.owner_guid = ".$user_query['guid']." order by m4.string asc limit 0,3";
      
     $entities = get_data($query, "entity_row_to_elggstar");

and it give this error...

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')) and (m4.name_id='318' AND m4.string >= )) and e.subtype= '12' and ( (1 = 1) a' at line 1

QUERY: SELECT distinct e.* from entities e JOIN objects_entity o on e.guid = o.guid JOIN (SELECT subm1.*, s1.string FROM metadata subm1 JOIN metastrings s1 ON subm1.value_id = s1.id) AS m1 ON e.guid = m1.entity_guid JOIN (SELECT subm2.*, s2.string FROM metadata subm2 JOIN metastrings s2 ON subm2.value_id = s2.id) AS m2 ON e.guid = m2.entity_guid JOIN (SELECT subm3.*, s3.string FROM metadata subm3 JOIN metastrings s3 ON subm3.value_id = s3.id) AS m3 ON e.guid = m3.entity_guid JOIN (SELECT subm4.*, s4.string FROM metadata subm4 JOIN metastrings s4 ON subm4.value_id = s4.id) AS m4 ON e.guid = m4.entity_guid where ((m1.name_id='298' AND m1.string IN ()) and (m4.name_id='318' AND m4.string >= )) and e.subtype= '12' and ( (1 = 1) and e.enabled='yes') and ( (1 = 1) and m1.enabled='yes') and ( (1 = 1) and m2.enabled='yes') and ( (1 = 1) and m3.enabled='yes') and ( (1 = 1) and m4.enabled='yes') and e.owner_guid = 2 order by m4.string asc limit 0,3