Question

How can I add mysql_real_escape_string to this search query?

mysql_query("SELECT * FROM logs WHERE text LIKE '%$text%'");

$text comes from a POST-funktion. I have tried a lot of combinations with no success.

TRIED:

mysql_query("SELECT * FROM logs WHERE text LIKE '" . mysql_real_escape_string(%$text%) . "'");
mysql_query("SELECT * FROM logs WHERE text LIKE 'mysql_real_escape_string(%$text%)'");
Was it helpful?

Solution

WHERE text LIKE '%".mysql_real_escape_string($text)."%'")
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top