Jump to content

Line Breaks (\r\n) & MySQL


kevinkorb

Recommended Posts

When I post a string from a textbox, I then clean it for mysql...

When I output the string to an update textarea, it actually comes out \r\n instead of the line breaks.

i.e.

$_POST['myTextArea'];
$clean = mysqli_real_escape_string($_POST['myTextArea']);

mysqli_query("INSERT INTO myTable (myVal) VALUES ('$clean');");

When getting the data back out

Say I entered in..

test1
test2
test3

my textbox populates

test1\r\ntest2\r\ntest3\r\n

when I do a stripslashes on it it outputs

test1rntest2rntest3rn

How do I get the database to recognize the breaks and not literal text?  Or how do I get the data out as planned?

Thanks.
Link to comment
https://forums.phpfreaks.com/topic/34818-line-breaks-rn-mysql/
Share on other sites

mysqli_real_escape_string shouldn't effect it, as \r and \n are invisible characters. Somewhere in your script it is causing this. What happens when you run nl2br on the string does it convert the \r\n in to a HTML line break ([nobbc]<br />[/nobbc])?
Link to comment
https://forums.phpfreaks.com/topic/34818-line-breaks-rn-mysql/#findComment-165070
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.