0

I am using: <textarea rows="24" name="thetext" cols="66"></textarea>

After submitting, I send it to MYSQL in a cell type (longtext)...

For example: I input:

Hello

world

All I get in the variable is helloworld(one word).. I need the line breaks..

I tried: $results = htmlentities($_POST[thetext]); and it is not working. How can I get it to show the line breaks please?

6
  • 1
    correct the implementation of text area like this <textarea rows="24" name="thetext" cols="66"></textarea> Commented Jan 29, 2014 at 10:47
  • have you tried $results =explode( "\r\n", $_POST['thetext'] ); Commented Jan 29, 2014 at 10:48
  • Shouldn't this happen automatically? Commented Jan 29, 2014 at 10:49
  • 1
    there is no <text area> in html only we have is <textarea> tag Commented Jan 29, 2014 at 10:50
  • 1
    why dont you post some more codes of html form and place where you read html form datas ? Commented Jan 29, 2014 at 10:53

3 Answers 3

1

A textarea will send new lines using \n\r, you need to convert that to HTML before outputting it to a page using nl2br($myVar);

In this case if you do:

echo nl2br($_POST['thetext']);

you will get Hello world with the line breaks in.

Sign up to request clarification or add additional context in comments.

1 Comment

I wanted to vote for you, but they again did not allow me, as this is my second question, I am new here
0

correct the implementation of text area like this

<textarea rows="24" name="thetext" cols="66"></textarea>

and use

nl2br($_POST[thetext])

instead of

htmlentities($_POST[thetext])

Comments

0

The easiest way is to change your rows/cells in the database to a ut8 collation charset. It should help you fix your problem.

Also the code I would use to send the form data to my database would be as follow:

$change_text = $_POST['thetext'];
$mysqli->query("YOUR_SQL_CODE");

And then to check if the data was sent correctly I would either access the row via the database directly or fetch the row like this:

if ($data = $mysqli->query("YOUR_SQL_CODE")) ;
$showtext = mysqli_fetch_row($data);
echo($showtext[0]);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.