Convert before saving into the database or save everything as is, then convert to html-safe equivalents when outputting to a web page.
That's essentially up to your requirements. If you will need the HTML version most of the time, it might be wise to safe it that way.
To quote your values from being misunderstood by the database: DBI.pm (if you're using that) has a quote() method/function that does the escaping of metacharacters for you the way your target database expects it (i.e. not HTML).
That seems to be done automatically if you are useing placeholders in your sql syntax, otherwise it's up to you to do it. Give it a try.
Update:
Convert to HTML code - which may or may be not safe, depending on what you include in the conversion.
Essentially double (") and single (') quotes could be seen as a threat to the DB. HTML encoding should have taken care of the former, making it ", but might not take care of the latter.
You might still need DBI::quote().
Update 2:
Zaxo adds: Be careful, semicolons are particularly unsafe with SQL. No time to relax on placeholders or quoting :-)
Cheers, Sören
|