Welcome Guest, Not a member yet? Register   Sign In
Insert Data
#1

[eluser]ann91[/eluser]
Hii...
I have a problem with this code..

this model
Code:
<?php
class FormModel extends CI_Model{
  
  function __construct(){
    parent::__construct();
  
  }
  
  function insert(){
    $data = array(
    "username" => $this->input->post('username'),
    "password" => $this->input->post('password'),
    "confpass" => $this->input->post('confpass'),
    "email"    => $this->input->post('email')
    );
    
  $this->db->insert('cust',$data);
  }
}
?>

and this Controller
Code:
<?php
class Form extends CI_Controller{
  
  function index(){
    $this->load->helper(array('form','url'));
    $this->load->library('form_validation');
    
    $this->form_validation->set_rules('username','Username','required|min_length[3]|max_length[5]');
    $this->form_validation->set_rules('password','Password','required|matches[confpass]');
    $this->form_validation->set_rules('confpass','Confirm Password','required');
    $this->form_validation->set_rules('email','Email','required|valid_email');
    
    
    if($this->form_validation->run()){
    
      if ($this->FormModel->insert($data))
      {
          $this->load->view('formSuccess');
        }
      else{
          $this->load->view('Myform');
        }
    }
    else{
          $this->load->view('Myform');
        }
  }
}
?>

I think this is a wrong controller code and i don't know, can you fix it..
Thanks before.. :lol:
#2

[eluser]oldmatt[/eluser]
Did you try:

Code:
$this->formmodel->insert($data)

instead of

Code:
$this->FormModel->insert($data)
#3

[eluser]ann91[/eluser]
I had try it.. but there is an error encountered..

Message error: Call to member function insert() on a non-object in Controller
#4

[eluser]InsiteFX[/eluser]
You need to load your model! Unless you are autoloading it.
Code:
<?php
class Form extends CI_Controller{
  
    public function __construct()
    {
        parent::__construct();
    }

    function index()
    {
        $this->load->helper(array('form','url'));
        $this->load->library('form_validation');
        $this->load->model('FormModel');

        $this->form_validation->set_rules('username','Username','required|min_length[3]|max_length[5]');
        $this->form_validation->set_rules('password','Password','required|matches[confpass]');
        $this->form_validation->set_rules('confpass','Confirm Password','required');
        $this->form_validation->set_rules('email','Email','required|valid_email');
    
        if ($this->form_validation->run())
        {
            if ($this->FormModel->insert($data))
            {
                $this->load->view('formSuccess');
            }
            else
            {
                $this->load->view('Myform');
            }
        }
        else
        {
            $this->load->view('Myform');
        }
    }
}

InsiteFX
#5

[eluser]ann91[/eluser]
i'm forget about that...
Thank's guys :lol:




Theme © iAndrew 2016 - Forum software by © MyBB