Page 1 of 1

maintaining formatting - forms to database

Posted: Sat Sep 27, 2003 8:58 am
by ukeventguide
this seems like a really easy question, which is why only i can't figure it out!

but on my site, users can input text using a text box and it is saved in a database. however, when it comes to retrieving it and displaying on a page, the paragraph formatting has gone, and if users have seperated text using line spaces, it appears as just one long blob??

any ideas on how i can fix this.

cheers

Posted: Sat Sep 27, 2003 10:10 am
by McGruff
Check out nl2br().

Posted: Sat Sep 27, 2003 10:31 am
by igoy

Code: Select all

<?

$textdata = nl2br($_post['usertext']);

$query = "INSERT INTO db.table (field_name) VALUES ($textdata)";

?>

now the retrived value will have line breaks as user had put..

Posted: Sat Sep 27, 2003 11:01 am
by ukeventguide
hey :D

thats great thanks - works a treat

Posted: Sat Sep 27, 2003 11:51 am
by McGruff
igoy wrote:now the retrived value will have line breaks as user had put..
Possibly it's better to do the nl2br'ing when you retrieve the text: that way the text stored in the db can be output in other ways as well as to the browser.