Welcome Guest, Not a member yet? Register   Sign In
Unknown column 'stud.id' in 'where clause'
#1

Hi! I encounter the error "Unknown column 'stud.id' in 'where clause'. I don't have any stud.id in my files and also in my database. What do you think the problem with this? I'm using Codeigniter 4.

Below is my code on my Controller:


Code:
    $model = new Mod_Stud();
    $id = $this->request->getVar('stud_id');

    $data = [
                'stud_id' => $this->request->getVar('stud_id'),
                'lname' => $this->request->getVar('lname'),
                'fname' => $this->request->getVar('fname'),
                'mname' => $this->request->getVar('mname'),
    ];

    $save = $model->update($id,$data);
    return redirect()->to( base_url('/') );

Code for my Model:

Code:
    protected $table = 'stud';
    protected $allowedFields = ['stud_id', 'sy', 'dpt', 'grd', 'lname', 'fname', 'mname', 'gender', 'bday', 'birthplace', 'religion', 'nationality', 'country', 'address', 'f_name', 'f_occ', 'm_name', 'm_occ', 'g_name', 'g_rel', 'created_at', 'updated_at'];
Reply
#2

You did not specify the primary key in your model.

I checked the documentation and it shows that when you use `update()` the first parameter should be the primary key indicated in your model. 

Assuming your primary key is stud_id. You should add this line to your model.

PHP Code:
$primaryKey 'stud_id'
Reply




Theme © iAndrew 2016 - Forum software by © MyBB