Jump to content

MySQL + PHP + INSERT


Go to solution Solved by Ch0cu3r,

Recommended Posts

Hello there,

 

I am currently struggling with something in regards to auto-line breaking when insterting into the MySQL database.

 

How could I make, so that when there's a line break (Pressing ENTER) for instance, whilst posting this topic, it's automatically breaking the lines for me.

 

How could I make it do that, as if I was creating a blog and I wanted it to be neater?

 

78ojO.png

 

 

Like there, you see that I've pressed "ENTER" twice, to get to a new line and another? How could I make it so it saves into the SQL database like that?

 

Many regards

Edited by iGetty
Link to comment
https://forums.phpfreaks.com/topic/286464-mysql-php-insert/
Share on other sites

  • Solution

The newlines are infact being saved in the database. The problem is the web browser ignores whitespace characters such as newlines. What you need to do is convert the newlines in to a HTML line break tag <br /> in order for the web browser to render the text on a new line.

 

PHP has a handy function to do this for you called nl2br

 

You'd use the function when outputting the data from the database

Edited by Ch0cu3r
Link to comment
https://forums.phpfreaks.com/topic/286464-mysql-php-insert/#findComment-1470394
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.