Welcome Guest, Not a member yet? Register   Sign In
[solved] Error: Call to a member function punch_in() on a non-object in
#1

[eluser]originalmmd[/eluser]
Hi all

I'm getting the following error when submitting the form in my application. New to CI and pretty much php, so I have no clue what's wrong.

My View
Code:
<?php
// load header template
$this->load->view('inc/html/header');
$this->load->helper('form');
$this->load->helper('date');
?>



<?php
// start page content
foreach($result as $row):?>  
  
  
<div data-role="collapsible-set">

  <div data-role="collapsible" data-collapsed="true" data-theme="b">
   <h3>&lt;?=$row->id?&gt; &lt;?=$row->name?&gt;</h3>
  
   &lt;!--codeigniter OPEN form--&gt;
   &lt;?php $attributes = array('class' => 'login', 'id' => 'login');
   echo form_open('employeeselect', $attributes); ?&gt;
   &lt;!--codeigniter open form--&gt;
  
   &lt;!--codeigniter buttons--&gt;
   &lt;?php
   foreach($person as $persons):
    
     form_hidden('projectid', $row->id);
     form_hidden('userid', $persons->id);
     form_hidden('date', now());
     $attributes = array('name' => 'mysubmit', 'data-role' => 'button', 'data-inline' => 'true','data-theme' => 'e');
     echo form_submit($attributes , $persons->firstname.' '.$persons->lastname);
    
    
   endforeach;
   ?&gt;
   &lt;!--codeigniter buttons--&gt;
  
  
   &lt;!--codeigniter CLOSE form--&gt;
   &lt;?php echo form_close(); ?&gt;
   &lt;!--codeigniter CLOSE form--&gt;
  </div>

</div>
&lt;?php endforeach;
// end page content
?&gt;  

&lt;?php
// load footer template
include 'inc/html/footer.php'
?&gt;


Controller:
Code:
&lt;?php  
        class employeeselect extends CI_Controller{  
            function index()  
            {  
                $this->load->model('employeeselect_model');
$this->load->database();    
      
                $data['result'] = $this->employeeselect_model->get_project();  
     $data['person'] = $this->employeeselect_model->get_person();
                $data['page_title'] = "CI Hello World App!";  
      
                $this->load->view('employeeselect_view',$data);  
            }  
  
   function punch()
   {
    //use the model to submit the posted data
    $this->load->database();
    $this->employeeselect_model->punch_in();
    
    redirect('employeeselect');
   }
        }  
    ?&gt;

Model
Code:
&lt;?php
class employeeselect_model extends CI_Model {


    function __construct()
    {
        // Call the Model constructor
        parent::__construct();
  $this->load->database();
    }
    
    function get_project()
    {
        $query = $this->db->get('project', 10);
        return $query->result();
    }

function get_person()
    {
        $query = $this->db->get('person');
        return $query->result();
    }

function punch_in()
{
  $this->load->database();
  $this->userid = $this->input->post('userid');
  $this->projectid = $this->input->post('projectid');
  $this->time = now();
  //$this->db->insert('punch',$this);
}
}
?&gt;

Any help would be appreciated
#2

[eluser]originalmmd[/eluser]
Ok, I solved that error by changing:
Code:
echo form_open('employeeselect', $attributes); ?&gt;
to
Code:
echo form_open('employeeselect', $attributes); ?&gt;

I uncommented the insert, but now it's not inserting any data.
#3

[eluser]the_unforgiven[/eluser]
Try
Code:
$data = array(
'userid'=>$this->input->post('userid'),
'projectid'=>$this->input->post('projectid'),
'time'=>now()
);
$this->db->insert('punch', $data);
return;

Instead of what you were doing

Code:
function punch_in()
{
  $data$this->load->database();
  $this->userid = $this->input->post('userid');
  $this->projectid = $this->input->post('projectid');
  $this->time = now();
  //$this->db->insert('punch',$this);
}




Theme © iAndrew 2016 - Forum software by © MyBB