如何通过PHP检查MySQL中没有空格的字符串

I have this query in PHP:

DELETE FROM table1 
where filename="'.$name.'" 
and id=(select id from table2 where cat="'.$category.'")

The problem is that the string $name is without whitespace and the relative field in table1 have them. How can I do this control?

SOLVED

I solved it with MySQL replace() function. Trim() function didn't work.

Use TRIM() :

DELETE FROM table1 where TRIM(filename) = "'.$name.'" and id = (select id from table2 where cat="'.$category.'")'

MySQL TRIM : http://www.w3resource.com/mysql/string-functions/mysql-trim-function.php

You can trim column values by using trim function .

DELETE FROM table1 where TRIM(filename) ="'.$name.'" and id=(select id from table2 where cat="'.$category.'")

http://www.w3resource.com/mysql/string-functions/mysql-trim-function.php