Results 1 to 2 of 2

Thread: Insert "Line Break" in the SQL dataBase

  1. #1
    Join Date
    Feb 2009

    Insert "Line Break" in the SQL dataBase


    I have the following content I want to insert into SQL database with the line break after each sentence, how should I do that?

    INSERT INTO tblTemplateEmail (EmailID, EmailBody)
    Values( 63,'Dear Manager First Name,,Welcome ! Your first step is to set up a Manager account in our system, as follows: Starting at website . Click on Manager login. Click on Setup an Account. Fill out all your information . MessageID:63.0.0')


  2. #2
    Join Date
    Aug 2004
    You should probably not have to do anything special other than using the normal newline character. When you retrieve it from the DB and want to display the data, then you might want to replace the newlines with HTML <br /> tags, which may be most easily done within your application code rather than the SQL. For instance, in PHP you can use the built-in nl2br() function:
    PHP Code:
    echo "<p>" nl2br($text_from_database) . "</p>\n"
    You might ask, "Why not just insert the <br /> tags into the database field?" If you do that, then you have output-specific data in there that you might not want in future uses of that data, which might mess up search functions you need to run on the data, etc.
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center