It is said that in order to prevent from SQL injection one should filter the input data eg. with addslashes or mysql_real_escape_string depending on used connection modules
However, data escaped with addslashes is being saved into the database WITH the slashes, so a user surname would save as O\’Reilly instead O’Reilly. The one needs to use stripslashes to display it correctly.
So how do I use addslashes and save into the database without slashes? Is it actually the way it should be done?
You DONT use
addslashesyou use the appropriate DB specific escaping function likemysql_real_escape_string.if you are using PDO then using a prepared statement will escape the variables as part of binding process. In this case all you need to do is something like:
OR for extra readability and esier reuse you can use named params: