Insert and fetch value in MYSQL through textarea tag

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • robin1983
    New Member
    • Oct 2007
    • 99

    Insert and fetch value in MYSQL through textarea tag

    Dear All,

    I am facing a problem when i display the data from mysql which i have inserted through textarea tag. I have a form where i copy and paste the details and submitted. But, when i fetch and display on the site, all the text are coming with any line break. its coming all in the same line which changes all the orginal paragraph format.

    Kindly help me how to overcome the same and i can display the same format which i have entered in the textarea.

    Thank you in advance.

    With Regrds,
    Robin
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hey.

    Textareas take their data as plain-text, in which line breaks are represented as a combination of the "\r" and "\n" characters. - HTML, on the other hand, does not recognize the plain-text line breaks. It uses the <br> tag as line-breaks (<br /> in XHTML).

    Which means that when you want to print plain-text data (such as the text from a textarea) into HTML, you need to convert the plain-text line-breaks to HTML line breaks.

    Like with most common tasks, PHP has a function that does this for you: the nl2br() function. See the manual entry for more details.

    Comment

    • robin1983
      New Member
      • Oct 2007
      • 99

      #3
      Thanks for quick response and it working properly but i face a new problem if the content that i copy contain the ' ' (single quote), the mysql is facing issue and it wont allowing to insert the data. can you please help me in ignoring the single quote.

      Thanks

      Comment

      • Atli
        Recognized Expert Expert
        • Nov 2006
        • 5062

        #4
        That is a very common problem. In fact, that is the #1 security problem PHP applications face.
        It's called SQL Injection; an attack on a database using purposefully malformed SQL statements.

        To protect against it, you must escape all characters in user input that MySQL might mistakenly parse as is if it were something other than text. The two best methods of dealing with this in PHP/MySQL is to use the mysql_real_esca pe_string function or Parameterized Statements. - The latter is arguably superior, but the former easier to use.

        Comment

        • robin1983
          New Member
          • Oct 2007
          • 99

          #5
          Dear Atil,

          Thank you very very much, now i have used mysql_real_esca pe_string function and its working properly. Thank you very very much for the help.


          I will be back incase i face any more issue.

          With Regards,

          Robin

          Comment

          Working...