On my server I have magic_quotes turned off. When a user save content as article in my DB from a form, I use
$text = mysql_real_escape_string($_POST['text']);
to prevent SQL Injecion.
This is my input <img src="image.png"></img>
and this is what it is saved in the DB <img src="image.png"></img>
When I echo htmlentities($row['text']);
i get <img src="image.png"></img>
printed on screen, on view source I get <img src="image.png"></img>
.
My questions are
- Isn't supposed to be saved in DB like
<img src=\"image.png\"></img>
to prevent SQL Injections ? - Is
htmlentities
is a good candidate to prevent XSS attacks? - Should I turn on magic_quotes?