How do I store formatted text into MySQL?
Posted 03 August 2006 - 12:45 AM
This is a test.
It would print out:
Hi, This is a test. Bye.
I'm submitting the user input into the database using POST method. If I do a manual "select * from..." in the mysql CLI, I can actually see the line breaks in the result. It's just that when PHP prints it, it leaves out the line breaks. Any help would be grateful! Thank!
Posted 03 August 2006 - 12:51 AM
$text = nl2br(stripslashes($text));
If you use mysql_real_escape_string or simular like you should, you would end up with slashes that need to be removed
Posted 03 August 2006 - 01:16 AM
Posted 03 August 2006 - 01:19 AM
if I have a string
$string = "Let's go to a party";
then the ' is escaped
Posted 03 August 2006 - 01:20 AM
not true with my database
You probably have magic_quotes_gpc turned on, and ken probably does not, which is a function of php not the database.
Posted 03 August 2006 - 01:25 AM
Posted 03 August 2006 - 01:30 AM
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. If magic_quotes_sybase is also on, a single-quote is escaped with a single-quote instead of a backslash.
Posted 03 August 2006 - 01:32 AM
They come back with slashes around single quotes
but all that matters at the end of the day, is that the script using works
using strip_slashes where there are no slashes does not do any harm
Posted 03 August 2006 - 02:03 AM
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users