473,473 Members | 1,902 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

problems with saving and retrieving data with new line (\n and \r\n)and slashes from mysql database

JM
Before storing information from a form in database I perform follwing
operations on it :
$path =
mysql_real_escape_string(strip_tags(trim(urldecode ($_POST['path']))));
$summary =
mysql_real_escape_string(strip_tags(trim(urldecode ($_POST['summary']))))

When I look in database I see '\r\n' in the text for the summary
wherever I pressed return-key.
When i retrieve the information from database and display it on webpage
'\r\n' is displayed even when I use
nl2br or
str_replace("\r\n", "<br/>", $content) or
str_replace(array("\r\n", "\n", "\r"), "<br>", $text) or
preg_replace("/\r\n|\n|\r/", "<br>", $text)
the '\r\n' is replaced with a <br>.
How is the possible ? The functions work when I let them handle a string
like "A little bit of\r\ntext".

A folder is stored as 'H:\\\\My Pictures\\\\Anemone.jpg' in the
database. When I want to display the folder I use the function
stripslashes first but then I still get 'H:\\My Pictures\\Anemone.jpg'.
Why should I apply stripslashes twice ?

Hope you can help me,

JM!
Jan 13 '07 #1
3 3594
In article <Ha*********************@scarlet.biz>, JM <re***@group.svp>
wrote:
Before storing information from a form in database I perform follwing
operations on it :
$path =
mysql_real_escape_string(strip_tags(trim(urldecode ($_POST['path']))));
$summary =
mysql_real_escape_string(strip_tags(trim(urldecode ($_POST['summary']))))

When I look in database I see '\r\n' in the text for the summary
wherever I pressed return-key.
When i retrieve the information from database and display it on webpage
'\r\n' is displayed even when I use
nl2br or
str_replace("\r\n", "<br/>", $content) or
str_replace(array("\r\n", "\n", "\r"), "<br>", $text) or
preg_replace("/\r\n|\n|\r/", "<br>", $text)
the '\r\n' is replaced with a <br>.
How is the possible ? The functions work when I let them handle a string
like "A little bit of\r\ntext".

A folder is stored as 'H:\\\\My Pictures\\\\Anemone.jpg' in the
database. When I want to display the folder I use the function
stripslashes first but then I still get 'H:\\My Pictures\\Anemone.jpg'.
Why should I apply stripslashes twice ?

Hope you can help me,

JM!
<snip>
magic_quotes_runtime boolean

If magic_quotes_runtime is enabled, most functions that return data
from any sort of external source including databases and text files
will have quotes escaped with a backslash.
</snip>

See get_magic_quotes_gpc() in the docs.

You can easily add code to account for this possibility:
get_magic_quotes_gpc() && $str = strip_tags( $str );

I'm also willing to bet that your line breaks are currently double
escaped e.g. "\\r\\n".

--
Koncept <<
"The snake that cannot shed its skin perishes. So do the spirits who are
prevented from changing their opinions; they cease to be a spirit." -Nietzsche
Jan 14 '07 #2
JM
Koncept wrote:
In article <Ha*********************@scarlet.biz>, JM <re***@group.svp>
wrote:
>Before storing information from a form in database I perform follwing
operations on it :
$path =
mysql_real_escape_string(strip_tags(trim(urldecod e($_POST['path']))));
$summary =
mysql_real_escape_string(strip_tags(trim(urldecod e($_POST['summary']))))

When I look in database I see '\r\n' in the text for the summary
wherever I pressed return-key.
When i retrieve the information from database and display it on webpage
'\r\n' is displayed even when I use
nl2br or
str_replace("\r\n", "<br/>", $content) or
str_replace(array("\r\n", "\n", "\r"), "<br>", $text) or
preg_replace("/\r\n|\n|\r/", "<br>", $text)
the '\r\n' is replaced with a <br>.
How is the possible ? The functions work when I let them handle a string
like "A little bit of\r\ntext".

A folder is stored as 'H:\\\\My Pictures\\\\Anemone.jpg' in the
database. When I want to display the folder I use the function
stripslashes first but then I still get 'H:\\My Pictures\\Anemone.jpg'.
Why should I apply stripslashes twice ?

Hope you can help me,

JM!

<snip>
magic_quotes_runtime boolean

If magic_quotes_runtime is enabled, most functions that return data
from any sort of external source including databases and text files
will have quotes escaped with a backslash.
</snip>

See get_magic_quotes_gpc() in the docs.

You can easily add code to account for this possibility:
get_magic_quotes_gpc() && $str = strip_tags( $str );

I'm also willing to bet that your line breaks are currently double
escaped e.g. "\\r\\n".
If I take get_magic_quotes_gpc() into consideration it now works fine
except for line feeds and carriage returns.

if (get_magic_quotes_gpc()) {
$sq = stripslashes($_POST['Summary']));
} else {
$sq = $_POST['ShortDesc'];
}
$Summary = mysql_real_escape_string(strip_tags(trim(urldecode ($sq))));

This code works for quotes en uri's. But whatever combinations I've
tried including using nl2br on storing and/or retrieving. It doesn't
work for line feeds and carriage returns.
Either \r\n is displayed on webpage or rn.

How to correctly store and retrieve input from a textarea (with LF and
CR) in MySQL ?

JM
Jan 15 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Geoff Soper | last post by:
I'm having problem with images becoming corrupted after loading them into a MySQL database and extracting them again. I'm pretty sure it's todo with escaping slashes but I'm at a loss as to how to...
3
by: Bert Sierra | last post by:
Hello -- I have what appears to be a simple PHP+MySQL query, but Dreamweaver consistently generates PHP code which won't parse. I've stared at the PHP code for several hours now, and I can't...
4
by: Bryan Powell | last post by:
Is it possible to grab data from a MySQL database and print it on the screen with VC++? The database is on a linux server if that would make any difference.
10
by: Krakatioison | last post by:
Hi everyone, can someone point me to download of an example for saving and retrieving to/from MYSQL database. Or did anyone of you tried this and could share your code with me. I've got some data...
3
by: Alina Ghergu | last post by:
Hi there, I'm currently developing a GUI for a network monitor. I have to plot data taken from a MySQL database. For GUI I use wxPython, for plotting Matplotlib. The plotting has to be realtime,...
0
by: ramyanet | last post by:
Dear all, Is there any way to directly transfer the data from excel to mysql database without using any tools,but thro coding. pls help me .hope i'll get a soln soon. Thanks Regds,
1
by: runway27 | last post by:
hi i have mysql database installed on the main webserver and i use a pc through the lan. i have couple of tables in different databases. my question is using php and mysql methods can i write a...
5
by: shuvo2k6 | last post by:
Hi, I am working on Remote Data Object (RDO) & MySQL in VB6. I cann't add record in my table. If anybody have Solution, Plz send me. Regards, shuvo2k6
2
by: secutos | last post by:
I have the option of storing data online as text files, or storing data online in a MySQL database. If the information is stored as a text file, all I have to do is a HttpWebRequest to the text file...
0
by: ahmurad | last post by:
Dear Brothers, I want to upload XLS/CSV huge data (90,000 rows in a XLS/CSV file) into MYSQL database. I want to use only Import option of phpmyadmin to upload XLS/CSV files. How can i to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.