1
<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');
        $this->load->model('templates');
        $data['msg']=$this->templates->update_email_template($content,$this->session->userdata('username'));
        $data['main_content']='message';
        $this->load->view('template',$data);

    }


function update_email_template($content,$username)
    {
        $data=array(
            'message'=>$this->input->post('email_message'));
            $this->db->where('username', $username);
            $this->db->update('email_format', $data); 
            return 'Successfully Updated';


    }
Aryan G
  • 1,281
  • 10
  • 30
  • 51

3 Answers3

2

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;
        }
        parent::__construct();
    }
}
/* 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"?

Community
  • 1
  • 1
Wesley Murch
  • 101,186
  • 37
  • 194
  • 228
0

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>

Jess
  • 8,628
  • 6
  • 49
  • 67
0

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.

Ibu
  • 42,752
  • 13
  • 76
  • 103