Welcome Guest, Not a member yet? Register   Sign In
Cannot modify header information - headers already sent by...?
#1

[eluser]anna16[/eluser]
Hi guys

How do i fix this error below?
http://www.coder9.com/ci/crud.php/welcome/contactus

This is the controller welcome.php
Code:
<?php
class Welcome extends Controller {

    function Welcome(){
        parent::Controller();
    }
    
    function index(){
        $this->load->helper('form');
        $data['title'] = "Welcome to our Site";
        $data['headline'] = "";
        $data['include'] = 'home';
        $this->load->vars($data);
        $this->load->view('template');
    }
    
    function contactus(){
        $this->load->helper('url');
        if ($this->input->post('email')){
            $this->load->model('MContacts','',TRUE);
            $this->MContacts->addContact();
            redirect('welcome/thankyou','refresh');
        }else{
            redirect('welcome/index','refresh');
        }
    }
    
    function thankyou(){
        $data['title'] = "Thank You!";
        $data['headline'] = "Thanks!";
        $data['include'] = 'thanks';
        $this->load->vars($data);
        $this->load->view('template');    
    }
}

/* End of file welcome.php */
/* Location: ./system/application/controllers/welcome.php */

This is the model below mcontacts.php
Code:
<?php
class MContacts extends Model{

    function MContacts(){
        parent::Model();
    }

     function addContact(){
        $now = date("Y-m-d H:i:s");
        $data = array(
            'name' => $this->input->xss_clean($this->input->post('name')),
            'email' => $this->input->xss_clean($this->input->post('email')),
            'notes' => $this->input->xss_clean($this->input->post('notes')),
            'ipaddress' => $this->input->ip_address(),
            'stamp' => $now
        
        );

        $this->db->insert('contacts', $data);    
     }
}
?>

I hope someone can give me good advice for this.
Thank you in advanced.
#2

[eluser]Developer13[/eluser]
Check your mcontacts.php file and make sure you don't have any extra spaces or linebreaks or anything after the PHP closing tag. The closing tag should be the very last thing in the file.
#3

[eluser]Vega[/eluser]
I don't think that you should have a closing tag in your model: http://ellislab.com/codeigniter/user-gui...losing_tag
#4

[eluser]Developer13[/eluser]
@Vega - Although you've hit a valid point that will ultimately provide a superficial solution to the problem of whitespace after the closing tag, and although it's "recommended practice", the omission of closing tags (even in PHP-only files) just doesn't seem like a proper solution. To me, it's kind of like turning error reporting off on warnings and notices to not be bothered with non-fatal issues an application might have just to be able to continue with bad programming practices.
#5

[eluser]anna16[/eluser]
@Vega

Thank you very much.




Theme © iAndrew 2016 - Forum software by © MyBB