Take the 2-minute tour ×
<textarea name="email_message" id="email_message" cols="65" rows="15"><?php echo trim($entry['message']);?></textarea>

When I update with above html code it make twice of blank line which contain in message.

eg :

Dear Sir
(here is one now now)
How are you?

when it update to database it save like :

Dear Sir
(here is two lines)

How are you?

It increase blank line in every save.

PHP code is here :

function email_template_save()
        $content = $this->input->post('email_message');


function update_email_template($content,$username)
            $this->db->update('email_format', $data); 
            return 'Successfully Updated';

share|improve this question
Can you please show the php-code you use to update the db? –  Dr.Molle Apr 24 '11 at 8:34
I have updated with PHP code. Thank you –  Aryan G Apr 24 '11 at 8:40
Would be good to see update_email_template() too. –  Dr.Molle Apr 24 '11 at 8:43
I have put that update_email_template() too –  Aryan G Apr 24 '11 at 9:00

3 Answers 3

up vote 2 down vote accepted

I know all about this, it's an issue with the latest release of CI and Windows newlines.

See this answer: PHP textarea saving extra new lines to MySQL DB

This is the workaround I'm using, extension of the input class:

<?php defined('BASEPATH') OR exit('No direct script access.');

 * CI 2.0 (Reactor version) did something funny to newlines.
 * Textareas would $_POST an extra newline, this is a patch for that "feature".
 * @package     Codeigniter
 * @subpackage  Input
class MY_Input extends CI_Input {

    public function __construct()
        if (PHP_EOL == "\r\n")
            $this->_standardize_newlines = FALSE;
/* end file */

This is related to your other question as well: explode error \r\n and \n in windows and linux server

See here for an explanation on that: When do I use the PHP constant "PHP_EOL"?

share|improve this answer

Is it possible that the blanks are represented going in as \r\n and when your print them, the \r and the \n separate? Try running <textarea name="email_message" id="email_message" cols="65" rows="15"><?php echo trim(str_replace("\r\n","\n",$entry['message']));?></textarea>

share|improve this answer
It is not working. I am running on windows (PHP 5.3). Is OS matter? –  Aryan G Apr 24 '11 at 8:37

It is possible that you are escaping the values twice, i had the same issue recently, check if you are escaping the value in both getting the post and in saving the data.

share|improve this answer

Your Answer


