Whats the best way to stop an SQL injection attack when passing LIKE qualifiers, % and _(underscore) to a query? i.e
$name = "%whatever";
$query = sprintf("SELECT name, role FROM usertable WHERE name LIKE $name)
The above is just an example and not ment to be used...
If you passed "%_" as the name in a $POST for example, it would return every record.
To stop this, you could do the following:
$name = "'" . addcslashes(mysql_real_escape_string($name), "%_") . "'";
The above would escape the qualifiers. Or you could just replace the qualifiers with some other characters.
The problem is that both % and _(underscore) are valid input characters. i.e you could have this stored in your database "Joe_Blogs". So escaping the LIKE qualifiers would break the data.
Question: What is the best way to stop injection attacks when using the LIKE?