Welcome Guest, Not a member yet? Register   Sign In
Redirect Load issues and Assigning property to a Non-Object
#1

[eluser]crispinatari[/eluser]
Hi! im having a tricky time understanding the problem i codeigniter, because my database deletes and adds new data through a form but it keeps giving me these errors

so annoying Sad

Quote:A PHP Error was encountered

Severity: Warning

Message: Attempt to assign property of non-object

Filename: controllers/emps.php

Line Number: 47
A PHP Error was encountered

Severity: Warning

Message: Cannot modify header information - headers already sent by (output started at W:\www\CI1\index.php:4)

Filename: helpers/url_helper.php

Line Number: 541

EMPS (controller)
Code:
function insertemp()
    {
    
    
     $data=$_POST;
     print_r($data);
      //if using helper
     $data->employeeID =$this->input->post('employeeID');
      //send the data to the insertemp function in the model
     $this->empsmodel->insertemp($data);
      //after insert, redirect back to main
    redirect('emps_page_two');


      
  }

EMPSMODEL.PHP
Code:
function insertemp($data)
     {
       $this->employeeID    = $data['employeeID'];
       $this->first_name = $data['first_name'];
       $this->last_name  = $data['last_name'];
         $this->departmentName    = $data['departmentName'];
        
        
        //$this->db->insert('emps', $this, $data);
       $this->db->insert('tblemployee', $this, $data);
     }
#2

[eluser]jcavard[/eluser]
Quote:A PHP Error was encountered

Severity: Warning

Message: Attempt to assign property of non-object
Filename: controllers/emps.php
Line Number: 47
This error is thrown because you $data is not an object, it's an array. You should do that instead $data['employeeID'];
Also, the $data = $_POST is useless, since later you assign this $data['employeeID'] = $this->input->post('employeeID');

EDIT (I JUST NOTICED THE DATA YOU INSERT IN YOUR MODEL): IF YOU REMOVE THE $DATA = $_POST, YOU MUST ADD THE FOLLOWING

Code:
function insertemp()
{
  //$data=$_POST; // remove this line
  print_r($data);

  //replace the $data = $_POST by this block of code
  $data['employeeID']      = $this->input->post('employeeID'); // this way, ['employeeID']
  $data['first_name']      = $this->input->post('first_name');
  $data['last_name']       = $this->input->post('last_name');
  $data['departmentName']  = $this->input->post('departmentName');

  //send the data to the insertemp function in the model
  $this->empsmodel->insertemp($data);
  //after insert, redirect back to main
  redirect('emps_page_two');
}

------

Quote:A PHP Error was encountered

Severity: Warning

Message: Cannot modify header information - headers already sent by (output started at W:\www\CI1\index.php:4)
Filename: helpers/url_helper.php
Line Number: 541[/color]
This error is thrown when there is something output to the page before the redirection is made. In this case the print_r($data); Remove the print_r line

Code:
function insertemp()
{
  $data=$_POST;
  //print_r($data); //<- This line needs to be commented out
  //if using helper
  $data->employeeID =$this->input->post('employeeID');
  //send the data to the insertemp function in the model
  $this->empsmodel->insertemp($data);
  //after insert, redirect back to main
  redirect('emps_page_two');
}

---

So try this code, and both errors should be gone
Code:
function insertemp()
{
  $data['employeeID'] = $this->input->post('employeeID');
  //send the data to the insertemp function in the model
  $this->empsmodel->insertemp($data);
  //after insert, redirect back to main
  redirect('emps_page_two');
}




Theme © iAndrew 2016 - Forum software by © MyBB