-1

im getting this error whenever i insert something into the database it insters the data but i recieve this error Message: Cannot modify header information - headers already sent by (output started at project/application/controllers/add_products.php:79)

function do_upload() {
        $config['upload_path'] = './assets/';
        $config['allowed_types'] = 'gif|jpg|png';
        $config['max_size'] = '2000';
        $config['max_width'] = '2000';
        $config['max_height'] = '2000';
        $config['new_image'] = './assets/';

        $config['overwrite'] = TRUE;
        $this->load->library('upload', $config);
        $this->form_validation->set_rules('name', 'Product Name', 'required|xss_clean');
        $this->form_validation->set_rules('description', 'Product Description', 'required|xss_clean');
        $this->form_validation->set_rules('price', 'Price', 'required');
        if (!$this->upload->do_upload() || !$this->form_validation->run()) {
            $error = array('error' => $this->upload->display_errors());
            redirect('add_products');
        } else {

            $data = $this->upload->data();
            $this->thumb($data);

             $category = $_POST["prod_category"];
            if($category  == "2")
                {
        $category = $_POST["other_category"];
            }
            $file = array(
                'img_name' => $data['raw_name'],
                'thumb_name' => $data['raw_name'] . '_thumb',
                'ext' => $data['file_ext'],
                'product_name' => $this->input->post('name'),
                'product_description' => $this->input->post('description'),
                'product_price' => $this->input->post('price'),
                'product_category' =>$category,    


            );

             // $this->db->insert("product_category",array("category"=>$category));
            $query = 'INSERT INTO product_category (id , category) VALUES (? , ?)
            ON DUPLICATE KEY UPDATE category=VALUES(category)';



              $this->User->insert_prod($file);
            $data = array('upload_data' => $this->upload->data());  
             echo '<script>alert("You Have Successfully Added a new Product!");</script>';       
            redirect('admin_products','refresh');
             $this->load->view('admin_products');

        }
    }
Christian
  • 259
  • 3
  • 7
  • 21
  • 1
    Possible duplicate of [How to fix "Headers already sent" error in PHP](http://stackoverflow.com/questions/8028957/how-to-fix-headers-already-sent-error-in-php) – Qirel Feb 09 '16 at 01:45

2 Answers2

0

remove line

echo '<script>alert("You Have Successfully Added a new Product!");</script>';
dhruv jadia
  • 1,684
  • 2
  • 15
  • 28
0

put ob_start(); after first < ?php line so your code should be:

<?php
ob_start();

it will turn on the output buffering