ngreenwood6 Posted December 17, 2008 Share Posted December 17, 2008 I have a form that users can fill out to make an entry into the database. The problem I have is that when it comes out of the database I want it to come out in the same formatting that the user had put it in. for example if they go to the next line to start a new paragraph I want it to show that instead of showing it all on the same line. any help is appreciated. Quote Link to comment Share on other sites More sharing options...
premiso Posted December 17, 2008 Share Posted December 17, 2008 look into using nl2br when pulling the data out of the database. Quote Link to comment Share on other sites More sharing options...
ngreenwood6 Posted December 17, 2008 Author Share Posted December 17, 2008 Is there anything that I should do when inserting the data into the database? Quote Link to comment Share on other sites More sharing options...
trq Posted December 17, 2008 Share Posted December 17, 2008 Is there anything that I should do when inserting the data into the database? Not in regard to formatting, you just need to make sure you escape any special chars as a security precaution. See mysql_real_escape_string. Quote Link to comment Share on other sites More sharing options...
redarrow Posted December 17, 2008 Share Posted December 17, 2008 you can use. mysql_real_escape_string(); // database security. or stripslashes(); // min um database security. or trim(); // make sure there no weight spaces. There many more Quote Link to comment Share on other sites More sharing options...
trq Posted December 17, 2008 Share Posted December 17, 2008 you can use. mysql_real_escape_string(); // database security. or stripslashes(); // min um database security. or trim(); // make sure there no weight spaces. There many more stripslashes provides NO security at all. In fact if used incorrectly it can open security holes. Quote Link to comment Share on other sites More sharing options...
Mchl Posted December 17, 2008 Share Posted December 17, 2008 Just stick to mysql_real_escape_string(), as it is the escaping function. stripslashes() is actually removing slashes from strings, and trim() is for stripping unnecessary whitespace. Quote Link to comment Share on other sites More sharing options...
ngreenwood6 Posted December 17, 2008 Author Share Posted December 17, 2008 I am already using mysql_real_escape_string. I was asking if there was anything to use for the formatting. My question is though, how does it know where to put a new line? If they just enter the text and put in some "enter's"(new lines), how does it know that they did that or is there something that I need to do. From looking into that nl2br it looks like I need to tell it where the \n needs to go. Can someone please clarify and maybe possibly an example? Quote Link to comment Share on other sites More sharing options...
Mchl Posted December 17, 2008 Share Posted December 17, 2008 When inserting data from form into database, newline characters ( \n \r \n\r ) are stored as their ASCII codes. Nothing you should do with them. It's just when you need to display them in HTML (which doesn't care about newlines), that you need to replace those with proper HTML tag. If you were to display that data into a textarea, you actually wouldn't need nl2br Quote Link to comment Share on other sites More sharing options...
trq Posted December 17, 2008 Share Posted December 17, 2008 \n are saved within the text when you hit enter. They are hidden, but trust me, they are there. nl2br simply find them and appends a <br /> after each occurance. You should only use nl2br when your actually displaying your data, not before saving it. Quote Link to comment Share on other sites More sharing options...
redarrow Posted December 17, 2008 Share Posted December 17, 2008 You dont see it in the database, But it there ^, each time a user hits the enter key, In the database it has a hidden ^ that how the database no there a brake... That why nl2br() works.. thorpe i was told it was a ^ character not a \n was i lied to again. Quote Link to comment Share on other sites More sharing options...
ngreenwood6 Posted December 17, 2008 Author Share Posted December 17, 2008 Ok I got it now. I was wondering because I was looking in the database for them and wasn't seeing them. So I just went ahead and tested it and it worked. Thanks for the help. Quote Link to comment Share on other sites More sharing options...
Mchl Posted December 17, 2008 Share Posted December 17, 2008 thorpe i was told it was a ^ character not a \n was i lied to again. ^ is a ^. Although someone might have used it to represent a newline character. See this Wikipedia article for some interesting background information http://en.wikipedia.org/wiki/Newline Quote Link to comment Share on other sites More sharing options...
redarrow Posted December 17, 2008 Share Posted December 17, 2008 Thanks mchi, went to ur website but there no English words. translate looks good and interesting ur website... Quote Link to comment Share on other sites More sharing options...
premiso Posted December 17, 2008 Share Posted December 17, 2008 Thanks mchi, went to ur website but there no English words. translate looks good and interesting ur website... Wikipedia may be setup to redirect you depending on what country you are in. But the en. part should make it English by default if I am not mistaken. Quote Link to comment Share on other sites More sharing options...
Mchl Posted December 17, 2008 Share Posted December 17, 2008 I guess he was talking actually about my website, where there are not many English words indeed Quote Link to comment 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.