English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Hi, I am just learning new programming languages and creating a website, not for a company just for my learning but i am stuck in a silly thing. I am using PHP and MySQL. And in HTML i am using TEXTAREA to write huge text. Basically if I write something like this:

This is first line,
This is second line.

When I store the above in MySQL database using TEXT datatype, and try to read it, it comes like this:

This is first line.This is second line.

They don't seem to come in separate lines.
Can you please tell me where the problem is.
Thankyou.

Oh, by the way this is the website i have created, still under construction:
http://www.sentosajaipur.com

2006-07-04 08:05:44 · 9 answers · asked by Manish 5 in Computers & Internet Programming & Design

But how can a user on my website will put
, in yahoo answer if i press enter, it comes in a new line, so don't know how to do that.

2006-07-04 08:09:48 · update #1

as per what FlpcNerds.com is saying, i know
is for breaking the line, but i know this and people who don't know computers, how can they put
code when writing something in different lines.

2006-07-04 08:13:11 · update #2

9 answers

Here is a better idea. I think the TEXTAREA return text with newline characters.

You are using php so replace newline characters with
before you store the text in the database. I believe the strtr() function will work.

Another thing you could do is use a specialized text area box meant for editing. There are text boxes out there that will automatically insert Html into the text that you could put in your webpage. I believe you could find one on hotscripts.com

2006-07-04 08:30:50 · answer #1 · answered by Anonymous · 3 1

When you read back the form text, you will have to convert line break instances (\n \r or whatever) to
tags before storing the text. Don't forget to escape the string after you alter it.

The line breaks might still be stored even if you don't handle them at post time.
If so, on output you would need to replace them with
tags.

2006-07-04 15:17:50 · answer #2 · answered by sheeple_rancher 5 · 0 0

in PHP there is a function n12br($var);
this function transforms every Enter press of the client in br tag...this is the solution to your problem....I'm web designer...if you want to chat with somebody about Web Design my messenger id is: lauriry_1991;
Stock the contain of the textarea in a variable then use the function on it before stocking the text into a database.
Good Luck!

2006-07-04 15:42:37 · answer #3 · answered by Yoda 2 · 0 0

You need the BREAKLINE tag..which is

I do not know exactly if MySQL accepts HTML tags perfectly..

But
is the HTML code for Breakline

example

This is first line,

This is second line.

will appear on a regular page as

This is first line,
This is second line.

2006-07-04 15:08:19 · answer #4 · answered by The Nerd 4 · 0 0

A SQL database field ignores the formatting of your web page field. As far as your database knows, it's just a string field. If you want the lines to be separate, you'll have to have separate fields in the database.

2006-07-05 01:50:49 · answer #5 · answered by birdiemum 2 · 0 0

Looks like you need a line break - not just pressing enter in your code.

2006-07-04 15:08:55 · answer #6 · answered by microsvc 5 · 0 0

When you read in the values from the db, parse the \r\n & convert it into
.

2006-07-04 19:25:08 · answer #7 · answered by Beatmaster 4 · 0 0

Try to use preformatted tags

 
.
They are working when you want to put many
spaces between words, maybe also good for
new lines too.

2006-07-04 15:16:06 · answer #8 · answered by San-diel 2 · 0 0

I suggest you to use dreamwaver, it will help you a little,

2006-07-04 16:21:44 · answer #9 · answered by !!! Radwan !!! 2 · 0 0

fedest.com, questions and answers