Hai provato a stampare $_POST['query'] per vedere se c'e` qualche carattere "fuori posto"?