Database Insertion
- Started
- Last post
- 20 Responses
- browncrown
Ok, so I have this site with a database and a form I made to insert the data into it.
That all works fine except for one thing. Part of the data includes a long text field for press release info. This info contains paragraphs. The form shows the paragraph breaks, but when the data is inserted and then viewed, the breaks are not there.
What gives?
- todelete__20
haha. you said insertion.
- JazX0
what type of dB man?
- determinedmoth0
HTML paragraphs? Could be stripped out by your DB.
- browncrown0
oops, the type of dB might be important, and I said insertion, another oops.
It is a MySQL dB. I get plenty of other things to work, but not this. Is there a function that could insert 's automatically or spit them out at viewing time?
- browncrown0
I have had success if I manually put the in my form field to place in the database. However, that gets annoying with long articles.
- seed0
You have to do a find and replace in your language that will replace the Returns as BR tags for instance.
- JazX0
I don't know. I use Domino Lotus Notes dBs. Although, it's overall the same concept. I just copy and paste HTML into a template based system. Ace though.
- seed0
Just curious what language/db are you using?
- browncrown0
php and mysql.
I have seen some functions in my google searching, but it is scrambling my brains this morning.
- determinedmoth0
Are you actually entering HTML in your script?
- determinedmoth0
string nl2br ( string string )
- Hello-Sexy0
when you read from the db, replace your linebreaks with a
- browncrown0
well, because I was ignorant of the situation, my text was coming out with no breaks. So, I went back and added 's manually. Now, they appear right, but if is not efficient for my end user. So, the string nl2br should be included when my script pulls the data from the db and I would need to remove the manual breaks I put in there. right?
- determinedmoth0
Right.
Everytime your user hits return in an HTML input box it enters a line break. You're converting these to br tags with nl2br.
- browncrown0
Awesome. I will give that a try. Thanks to all for the help and time. Hope I don't have to revive the thread.
- browncrown0
well, I had to unfortunately revive this thread. I have tried to use the function, but have nothing to show from it.
My text in the source code is being spit out like it was entered in the database, but, the function is not inserting the so it looks like garbage.
Does nl2br need to happen when I insert data into the database or can it happen when it is being pulled out.
- JazX0
LAMP
- determinedmoth0
Use it when you echo it.
echo nl2br ($text);
- browncrown0
got it. I was just being careless in my mysql echo stuff. I was trying to use the function on the wrong part.
crawling into corner.
thanks
- determinedmoth0
no problem.