Jump to content


Photo

Problem with text format pulling from mysql field


  • Please log in to reply
4 replies to this topic

#1 stone140

stone140
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 12 October 2006 - 08:20 PM

When I am retrieving a "text" field from my mysql database the new lines (that the user entered) are no longer there when I display the field.  It is simly one continual line of text.  Has anyone ever run into this problem before - if so how did you fix it?


#2 Wuhtzu

Wuhtzu
  • Members
  • PipPipPip
  • Advanced Member
  • 702 posts
  • LocationDenmark -> Fyn -> Aarup

Posted 12 October 2006 - 08:25 PM

If the user posted/entered the text (like a comment or so) using a <textarea> on your page the linebreaks will disappear if you just insert $_POST['text'] into your mysql-database. Instead you should insert nl2br($_POST['text']). This will preserve the linebreaks...
Feel free to correct me if I'm wrong.

Servage.net: Get 25 Gb of extra storeage by using this coupon code when buying their hosting service - http://www.servage.n...oupon=cust42005

#3 stuart.cole

stuart.cole
  • Members
  • PipPip
  • Member
  • 16 posts

Posted 12 October 2006 - 08:37 PM

I had exactly the same issue recently -

If you read this post you can see the help I received - which I have now got working

Check out huggies answer...

#4 alpine

alpine
  • Members
  • PipPipPip
  • Advanced Member
  • 756 posts
  • LocationNorway

Posted 12 October 2006 - 08:39 PM

If the user posted/entered the text (like a comment or so) using a <textarea> on your page the linebreaks will disappear if you just insert $_POST['text'] into your mysql-database. Instead you should insert nl2br($_POST['text']). This will preserve the linebreaks...


It is much better practice to use nl2br() when outputting data

#5 stone140

stone140
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 12 October 2006 - 08:41 PM

You guys are lifesavers.  Thanks!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users