Current location: Hot Scripts Forums » Programming Languages » PHP » How do I get line breaks to carry over from form to database?

How do I get line breaks to carry over from form to database?

Reply
  #1 (permalink)  
Old 03-30-04, 01:56 PM
Poodle Tosser Poodle Tosser is offline
New Member
 
Join Date: Mar 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
How do I get line breaks to carry over from form to database?

I've created a very simple form using PHP that allows a user to add/delete/update the news items on a homepage.

The form asks a user to enter a Title, Date, and Article which are then uploaded to the corresponding fields in the MySQL database.

My problem is that the line breaks in the Article input area don't carry over to the database. For instance, if I cut and paste a 2 paragraph article from Word into the form, it just shows as one paragraph once it reaches the website.

Is there a way to make sure the appropriate <br> or <p> tags are inserted into the copy on it's way to the database?

I hope this is clear.

Thanks,
Glenn
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 03-30-04, 09:51 PM
blaw's Avatar
blaw blaw is offline
Junior Code Guru
 
Join Date: Dec 2003
Location: Vancouver, BC, Canada
Posts: 550
Thanks: 0
Thanked 0 Times in 0 Posts
Hi there,

The line break is represented as \n in text format and this will be saved as is in your database. You don't see it (well you do, in a form of line break), but try replacing this thing with <br /> when you output it as HTML. Use str_replace() for this job. It's fast.

HTH.
__________________
Blavv =|
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 03-31-04, 07:34 AM
stan's Avatar
stan stan is offline
New Member
 
Join Date: Mar 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
agree.
nl2br() also works..
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 03-31-04, 07:50 AM
NeverMind's Avatar
NeverMind NeverMind is offline
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,250
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by stan
agree.
nl2br() also works..
actually nl2br() was created just for this! so it's faster ..
__________________
We don't need a reason to help people - Zidane [FF9]
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Redirection back to a page from form submit DAL Perl 11 03-21-05 02:45 PM
formmail problem gscraper Perl 12 08-27-04 03:06 AM
asp-iis-Server error nsuresh_rasr ASP.NET 3 02-08-04 12:47 AM
SQL database registration form help vinhkhuong PHP 3 10-10-03 03:49 AM
Need to submit form to database and text file - Any ideas how? dpreiss ASP 1 08-21-03 06:02 PM


All times are GMT -5. The time now is 08:00 PM.
vBulletin® Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.