PHP/MYSQL - lines break up on db insert

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
cjkeane
Forum Contributor
Posts: 217
Joined: Fri Jun 11, 2010 1:17 pm

PHP/MYSQL - lines break up on db insert

Post by cjkeane »

Hi everyone,

I'm having n issue with how data appears when inserted in a db. When the data is inserted into the db, it goes in like so:

This is another test to see if long lines of text break up.
This is another
test to see if long lines of text break up. This is another
test to see if
long lines of text break up

but it should appear as one long paragraph of text and wrap around, eg:

This is another test to see if long lines of text break up. This is another
test to see if long lines of text break up. This is another test to see if
long lines of text break up

any ideas why this would be happening?
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: PHP/MYSQL - lines break up on db insert

Post by social_experiment »

Do you add line breaks (br tags) when you pass the code to the database? You can try using <pre> tags to display the data in your format
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
cjkeane
Forum Contributor
Posts: 217
Joined: Fri Jun 11, 2010 1:17 pm

Re: PHP/MYSQL - lines break up on db insert

Post by cjkeane »

no i don't add any line breaks which is why i was asking why it might be happening. i'll look into the pre tag and see if it helps. thanks.
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: PHP/MYSQL - lines break up on db insert

Post by social_experiment »

Apparently line breaks are stored as "\n" which the browser ignores.
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
cjkeane
Forum Contributor
Posts: 217
Joined: Fri Jun 11, 2010 1:17 pm

Re: PHP/MYSQL - lines break up on db insert

Post by cjkeane »

yes, i realize that. i've looking in the actual db and the field. there are no br's or \n's or \r\n's.
Post Reply