I have a SQL query that goes like this:
UPDATE User SET flag='Y' WHERE email=(SELECT email FROM Forum WHERE id='$id');
Because the email address can consist of single quotes and some special characters (s*a'{f`%$.=*+~&^#|g!/hd@[66.112.45.34] and vy.”(),:;<>[]”.VY.”vy\\ \@\”vy”.unal@str.exe.com are both valid email addresses), I am not sure whether it is necessary to do the subquery separately, escape the output, followed by using it in the main query.
What is your suggestion?
ADD NOTE: $id is a safe number.
You don’t need to escape anything because there is a subquery, but of course you need to escape the
idvalue to put it in the string.If possible, you should use a parameterised query instead of concatenating the value into the string. Then you don’t have to escape anything.