Ok, I’ve been playing around with this.
I made a simple demo page:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>DB fun</title>
</head>
<body>
<form method="post" action="donboe_db.php">
<textarea name="sometext" rows="10" cols="50"></textarea>
<input type="submit" value="Submit" name="submit" />
</form>
</body>
</html>
On this page I entered the following into the text area:
Some text
More text
Even more text
I submitted the form to a small PHP script, which inserted it into the database:
<?php
$conn = new PDO('mysql:host=localhost;dbname=sitepoint', '****', '****');
$sometext = $_POST['sometext'];
$sql = "INSERT INTO donboe (sometext) VALUES (:sometext)";
$q = $conn->prepare($sql);
$q->execute(array(':sometext'=>$sometext));
?>
Then I dumped the table and got this:
--
-- Table structure for table `donboe`
--
CREATE TABLE IF NOT EXISTS `donboe` (
`sometext` varchar(255) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
--
-- Dumping data for table `donboe`
--
INSERT INTO `donboe` (`sometext`) VALUES
('Some text\\r\
\\r\
Some more text\\r\
\\r\
Even more text');
As you can see, the line breaks from the text area ended up as \\r\
, presumably as I’m on Linux.
I then modified my initial script to fetch the value from the db and display it in the text area:
<?php
$pdo = new PDO('mysql:host=localhost;dbname=sitepoint', '****', '****');
$select = 'SELECT sometext';
$from = ' FROM donboe';
$sql = $select . $from;
$statement = $pdo->prepare($sql);
$statement->execute();
$results=$statement->fetchColumn();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>DB fun</title>
</head>
<body>
<form method="post" action="donboe_db.php">
<textarea name="sometext" rows="10" cols="50"><?php echo $results; ?></textarea>
<input type="submit" value="Submit" name="submit" />
</form>
</body>
</html>
And I saw:
Some text
More text
Even more text
formatted correctly.
I’m not sure how this helps you, but it was interesting that I couldn’t reproduce your issue at all.
To move this forward:
Could you do a dump of your DB table and let us see how the line breaks are being stored.
Please post the relevant parts of the results here.