All variations on the same theme:
$bar = "O'Reilly"; "foo = '$bar'"; // foo = 'O'Reilly' -> invalid syntax
Blindly concatenating strings together can lead to syntax violations if strings must follow special syntax. At best, this is an annoyance; at worst, a security issue. Equivalent values โโprevent these problems. General example:
"foo = '" . escape($bar) . "'"; // foo = 'O\'Reilly'
All the various functions correctly escapes values โโfor different syntaxes:
htmlentities for outputting output for HTML.
mysql_real_escape_string for escaping values โโfor SQL queries.
addslashes ... not very good for anything, do not use.
json_encode for encoding / escaping / converting values โโfor Javascript format.
source share