Welcome Guest, Not a member yet? Register   Sign In
How can i initialize a userdefined variable.
#10

[eluser]Michael Wales[/eluser]
I did read the post from the beginning and I am trying to help. Let's see if we can break this down a little futher:

Here you are inserting 2 columns: action and master_name.
Code:
INSERT INTO `master` (`action`, `master_name`) VALUES (NULL, ‘sdf’)

Here you are inserting 1 column: master_name.
Code:
$data = array(‘master_name’ => $this->input->post(‘master_name’));
$query = $this->db->insert(‘master’, $data);

In the code you have show us, thus far, the only place in which action is referenced is:
Code:
$this->action = 'insert';

So, even though the code you are showing us is this:
Code:
$data = array(‘master_name’ => $this->input->post(‘master_name’));
$query = $this->db->insert(‘master’, $data);

In reality, it looks like this:
Code:
$data = array(‘master_name’ => $this->input->post(‘master_name’));
// ... Do some other stuff here to add an action key to the $data array ...
$query = $this->db->insert(‘master’, $data);

If you would like help in debugging this problem, please share the relevant code in it's entirety.

To do what you want - your code should look something like this:
Code:
class Model_name extends Model {

  var $id;

  function insert($data) {
    $this->db->insert('master', $data);
    if ($this->db->affected_rows() > 0) {
      $this->id = $this->db->last_insert_id();
      return TRUE;
    }

    return FALSE;
  }

}


Code:
class Controller_name extends Controller {

  function index() {
    $this->load->model('model_name');
    if ($this->model_name->insert(array('master_name' => $this->input->post('master_name'))) {
      echo 'Inserted ID: ' . $this->model_name->id;
    } else {
      echo 'Did not insert data.';
    }
  }

}


Messages In This Thread
How can i initialize a userdefined variable. - by El Forum - 10-22-2009, 04:07 AM
How can i initialize a userdefined variable. - by El Forum - 10-22-2009, 04:15 AM
How can i initialize a userdefined variable. - by El Forum - 10-22-2009, 04:37 AM
How can i initialize a userdefined variable. - by El Forum - 10-22-2009, 04:41 AM
How can i initialize a userdefined variable. - by El Forum - 10-22-2009, 04:57 AM
How can i initialize a userdefined variable. - by El Forum - 10-22-2009, 10:08 PM
How can i initialize a userdefined variable. - by El Forum - 10-23-2009, 03:25 AM
How can i initialize a userdefined variable. - by El Forum - 10-23-2009, 06:11 AM
How can i initialize a userdefined variable. - by El Forum - 10-23-2009, 06:14 AM
How can i initialize a userdefined variable. - by El Forum - 10-23-2009, 06:38 AM
How can i initialize a userdefined variable. - by El Forum - 10-23-2009, 07:00 AM
How can i initialize a userdefined variable. - by El Forum - 10-23-2009, 07:18 AM



Theme © iAndrew 2016 - Forum software by © MyBB