I have a dilemma how should I mysql_real_escape_string() my variables without inserting them into the database \n, \r, \x00 when someone uses " ' or <br> on my comment field, I tried with preg_replace instead of mysql_real_escape_string, but seems I don’t know exactly how to allow all the chars and signs I want.
I have a dilemma how should I mysql_real_escape_string() my variables without inserting them into
Share
You should be able to use str_replace to help with this:
Having said that, it is a good idea to switch to mysqli or PDO for database read / write. Both of these allow prepared statements, which reduce the risk of SQL injections.
Here’s an example of PDO: