note 85265 added to function.mysql-real-escape-string
| From: | tomasdotehrlichatgmaildotcom at osu1 dot php dot net | Date: | Fri, 22 Aug 2008 15:14:36 +0000 |
| Subject: | note 85265 added to function.mysql-real-escape-string | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-143752@lists.php.net to get a copy of this message | ||
Reply to: zareef at zareef dot net
If you simply print escaped string, new lines and carriage returns will be changed to literal \n and
\r, as you say.
When you put this string to the database and take it back, everythink seems to be ok:
<?php // Example:
$msg = mysql_real_escape_string ("hi,\nI'm the new line");
// echo $msg shows: hi,\nI'm the new line
$sql = sprintf ('INSERT INTO test (msg) VALUES ("%s")', $msg);
mysql_query ($sql);
$sql = 'SELECT msg FROM test';
$res = mysql_query ($sql);
$item = mysql_fetch_assoc ($res);
echo $item['msg'];
?>
Now we get:
hi,
I'm the new line
----
Server IP: 212.24.129.51
Probable Submitter: 85.132.163.48
----
Manual Page -- http://www.php.net/manual/en/function.mysql-real-escape-string.php
Edit -- https://master.php.net/note/edit/85265
Del: integrated -- https://master.php.net/note/delete/85265/integrated
Del: useless -- https://master.php.net/note/delete/85265/useless
Del: bad code -- https://master.php.net/note/delete/85265/bad+code
Del: spam -- https://master.php.net/note/delete/85265/spam
Del: non-english -- https://master.php.net/note/delete/85265/non-english
Del: in docs -- https://master.php.net/note/delete/85265/in+docs
Del: other reasons-- https://master.php.net/note/delete/85265
Reject -- https://master.php.net/note/reject/85265
Search -- https://master.php.net/manage/user-notes.php