maintaining formatting - forms to database

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
ukeventguide
Forum Newbie
Posts: 2
Joined: Sat Sep 27, 2003 8:58 am

maintaining formatting - forms to database

Post 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
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

Check out nl2br().
User avatar
igoy
Forum Contributor
Posts: 203
Joined: Fri May 02, 2003 11:57 pm
Location: India
Contact:

Post 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..
ukeventguide
Forum Newbie
Posts: 2
Joined: Sat Sep 27, 2003 8:58 am

Post by ukeventguide »

hey :D

thats great thanks - works a treat
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post 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.
Post Reply