Tinple
Tinple

Reputation: 191

CI Database Error

I'm freshman in CI. Today I got an error like this when I learned CI tutorial. You must use the "set" method to update an entry.

Filename: F:\xampp\htdocs\ISA2013\ISA2013\system\database\DB_active_rec.php

Line Number: 1174

My Model code like this.

class Apply_model extends CI_Model {
    public function add_record($data){
        $query = $this->db->insert('help_user');
        //return;
    }
}

And I just coded like that in Control:

public function create(){
        $data = array('USER_NUMBER' => $this->input->post('stuNO'),
                      'USER_EMAIL'  => $this->input->post('email'),
                      'USER_INFO'   => $this->input->post('info')
                    );
        $this->apply_model->add_record($data);
        $this->index();
}

..when I run class/create, I got the top of error.. Can someone help me?

Upvotes: 1

Views: 1706

Answers (5)

Tofan
Tofan

Reputation: 31

on your model you must like this

public function add_record($data)
    {

        $this->db->insert('help_user',$data); //it's more be simple 
    }

if you write a return; you will return a null value to your controller if you write like

$query = $this->db->insert('help_user');

you just make a variable $query with value $this->db->insert('help_user'); so thats make a error

Upvotes: 1

cold coffe
cold coffe

Reputation: 13

hey buddy you are missing one parameter and you are not returning the value, you should have

return $this->db->insert('help_user', $data);

Upvotes: 0

Charles0429
Charles0429

Reputation: 1420

You don't pass the parameter data into $this->db->insert function. You can change the code line :

$query = $this->db->insert('help_user');

to:

$query = $this->db->insert('help_user', $data);

Upvotes: 1

Altaf Hussain
Altaf Hussain

Reputation: 5202

As mentioned by nevermind, you have to pass data array to the insert function. Also please note that data array should be an associative array, where keys will be the table fields and values will be values for the fields.

Upvotes: 1

kdeveloper
kdeveloper

Reputation: 95

You need to pass your data as parameter to $this->db->insert function as mentioned by nevermind

Upvotes: 2

Related Questions