Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Codeigniter error message Cannot modify header information

I got this error message when i run my php CodeIgniter project:

A PHP Error was encountered

Severity: Warning

Message: Cannot modify header information - headers already sent by (output started at C:\AppServ\www\tree\application\models\mtree.php:17)

Filename: core/Common.php

Line Number: 442

line 17:

echo $row->members_id . "</br>";

this is my model function:

function convert_all() {
    $this->db->empty_table('table1');
    $this->db->empty_table('table2');
    $this->db->query("INSERT INTO `table1` (`members_id`, `members_username`);
    $query = $this->db->get('table2');
    foreach ($query->result() as $row) {
        if ($row->members_id > 1) {
            echo $row->members_id . "</br>";
        }
        if ($this->isadvanced($row->members_id, $row->members_direct_id)) {
            $this->insert_to_right($row, $row->members_direct_id);
        } else {
            $this->insert_to_left($row, $row->members_direct_id);
        }
    }
}
like image 654
user2988211 Avatar asked May 11 '26 03:05

user2988211


1 Answers

While using codeigniter, its best recommended that you echo only in views.

Echoing anywhere randomly sends some data to browser, after which you can't modify headers (this includes attempt to redirect, set content-type, etc)

You should re-organize your code, such that, echo are done within views only. This will solve your header issues in Codeigniter.

This also includes extra whitespaces at the end after the closing brace "} ?>" in non-view php files.

like image 195
linuxeasy Avatar answered May 12 '26 20:05

linuxeasy