Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why are the line breaks gone when I retrive data from my SQL database?

I’ve made a site where the user can type somthing in a textarea. The text is then saved to a databse I have at phpMyAdmin. However, when I retrive the data from the database, and ‘echo’ it on the screen, all the line breaks the user have included, is gone.

Does anyone have a solution for this?

I’ve tried with different things like including a button for ‘new line’ in the UI, but that’s not very convenient. I wonder if there’s any other way of displaying the line breaks?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

If you want to display the text exactly as it was entered on a web page, perhaps a <pre></pre> block may work best for you.

It would be best if you did more to sanitize any user-provided text you intend on returning to a browser, though, to avoid XSS and other exploits.

For example, what if a user sent you a script block, and you returned that to any one’s browser?

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading