Currently getting more and more into MySQL. It's something i haven't been too fussed about but i want to write some scripts with it now.
My question is simple, im making a search script and just want to know if my php code can prevent some SQL injections.. the code:
$orig = $_POST['term']; $term = mysql_real_escape_string($orig); $sql = mysql_query("select * from db1 where content like '%$term%' "); Is this ok? Alternatively if anyone has an easier/better/safer way of doing this plese feel inclined to let me know.
PDOor, at the very least, start usingMySQLi. You will do the world a great service :)mysql_escape_string()was also "probably safe" until it was discovered that it wasn't.mysql_escape_stringThis function is identical to mysql_real_escape_string() except that mysql_real_escape_string() takes a connection handler and escapes the string according to the current character set. mysql_escape_string() does not take a connection argument and does not respect the current charset setting.