Question
htmlentities vs mysql_real_escape_string
Stupid question but what's the difference between
htmlentities & mysql_real_escape_string; they both seem to be
designed against hackers keying in html instructions into forms so
they 'escape' problem strings (primarily the apostrophe it seems)
and I know that you use mysql_real_escape_string before writing to
a db and htmlentities before re-display user in put on a screen but
why is this separateion necessary - why can't it just be one
function?
Playing around I can see that if I enter <p echo 'me' /p>, MRES gives me <p echo \'me\' /p> (with magic quotes slashes striped), and htmlentities give me Null so there is clearly a dfference but I don't understand why - can anyone explain in simple words for a simple brain?
Also does this mean that when validating prior to writing to a db I validate an htmlentities version of the input but then write a MRES version to the db? In the example above I would be validating a null string and if it was not a mandatory field I would end up writing a line of code (albeit escaped) to my db?
Thanks.
Playing around I can see that if I enter <p echo 'me' /p>, MRES gives me <p echo \'me\' /p> (with magic quotes slashes striped), and htmlentities give me Null so there is clearly a dfference but I don't understand why - can anyone explain in simple words for a simple brain?
Also does this mean that when validating prior to writing to a db I validate an htmlentities version of the input but then write a MRES version to the db? In the example above I would be validating a null string and if it was not a mandatory field I would end up writing a line of code (albeit escaped) to my db?
Thanks.
