I want to input multiple lines in a textarea field in a form, how can I keep(save) the carriage return into MYSQL database, and re-display in the web page?

If I only use $_POST['textarea_name'], then update it into MYSQL, then retrieve it to display it , all carriage returns disappear.

Thanks a lot.

    Actually, the newlines do not disappear, they are just treated as a word space by the browser unless within a <pre> tag (or another tag with the style property of "white-space:pre;"). If you want the browser to output line breaks, use PHP's [man]nl2br/man function when you output the text to the client.

      NOGDOG, Thank you first.

      This is a bad news, I have to ask the user add "<br/>" at the end of every paragraph.

      Any Master has a better suggestion?

        Uh...no...I said nothing about the user adding <br/>. I did suggest that you use the [man]nl2br/man function when outputting the text from the DB to the browser. For a simplistic example:

        $data = mysql_query('SELECT text FROM table');
        while ($row = mysql_fetch_assoc($data))
        {
           echo "<p>".nl2br($row['text'])."</p>\n";
        }
        

          Great! You're right! NogDog!

          No need to add <br/>, only use nl2br!

            Write a Reply...