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


In reply to Re: Format to save and display by Happy-the-monk
in thread Format to save and display by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.