colinexl Posted August 3, 2006 Share Posted August 3, 2006 Hi all, I have a message board that will store user input into a mysql database. The input is much like a forum input like the one i'm typing in now. It's able to store line returns etc. I'm using a LONGTEXT to store the user inputs but when I print it back using PHP, it gives one long time of text. For example if the user typed:Hi,This is a test.Bye.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! Quote Link to comment https://forums.phpfreaks.com/topic/16395-how-do-i-store-formatted-text-into-mysql/ Share on other sites More sharing options...
kenrbnsn Posted August 3, 2006 Share Posted August 3, 2006 Use the nl2br() function when you send the text to the browser for displaying. (http://www.php.net/nl2br)Ken Quote Link to comment https://forums.phpfreaks.com/topic/16395-how-do-i-store-formatted-text-into-mysql/#findComment-68226 Share on other sites More sharing options...
onlyican Posted August 3, 2006 Share Posted August 3, 2006 When ever I get text from a Mysql TableI use$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 Quote Link to comment https://forums.phpfreaks.com/topic/16395-how-do-i-store-formatted-text-into-mysql/#findComment-68228 Share on other sites More sharing options...
kenrbnsn Posted August 3, 2006 Share Posted August 3, 2006 Whenever I use mysql_real_escape_string() when I insert data, I don't have to use stripslashes() when I pull the data out. If you look at the data in the database, it's stored without the slashes.Ken Quote Link to comment https://forums.phpfreaks.com/topic/16395-how-do-i-store-formatted-text-into-mysql/#findComment-68243 Share on other sites More sharing options...
onlyican Posted August 3, 2006 Share Posted August 3, 2006 not true with my databaseif I have a string$string = "Let's go to a party";then the ' is escaped Quote Link to comment https://forums.phpfreaks.com/topic/16395-how-do-i-store-formatted-text-into-mysql/#findComment-68247 Share on other sites More sharing options...
hitman6003 Posted August 3, 2006 Share Posted August 3, 2006 [quote]not true with my database[/quote]You probably have magic_quotes_gpc turned on, and ken probably does not, which is a function of php not the database. Quote Link to comment https://forums.phpfreaks.com/topic/16395-how-do-i-store-formatted-text-into-mysql/#findComment-68249 Share on other sites More sharing options...
kenrbnsn Posted August 3, 2006 Share Posted August 3, 2006 I have magic_quotes_gpc turned [b]on[/b] and magic_quotes_runtime turned [b]off[/b]. It's the second setting that is affecting pulling data from the database (I believe).Ken Quote Link to comment https://forums.phpfreaks.com/topic/16395-how-do-i-store-formatted-text-into-mysql/#findComment-68251 Share on other sites More sharing options...
hitman6003 Posted August 3, 2006 Share Posted August 3, 2006 I was unfamiliar with that (magic_quotes_runtime) until just now...here's what the manual says about it:[quote]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. If magic_quotes_sybase is also on, a single-quote is escaped with a single-quote instead of a backslash. [/quote] Quote Link to comment https://forums.phpfreaks.com/topic/16395-how-do-i-store-formatted-text-into-mysql/#findComment-68256 Share on other sites More sharing options...
onlyican Posted August 3, 2006 Share Posted August 3, 2006 All i know, when I use <textarea>They come back with slashes around single quotesbut all that matters at the end of the day, is that the script using worksusing strip_slashes where there are no slashes does not do any harm Quote Link to comment https://forums.phpfreaks.com/topic/16395-how-do-i-store-formatted-text-into-mysql/#findComment-68257 Share on other sites More sharing options...
colinexl Posted August 3, 2006 Author Share Posted August 3, 2006 Hey thanks for the replies. I will give it a try soon =) Quote Link to comment https://forums.phpfreaks.com/topic/16395-how-do-i-store-formatted-text-into-mysql/#findComment-68268 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.