Search code examples
phpcodeigniter-4

Problem with "A PHP Error was encountered : Undefined Index"


i have a problem with my code and i don't know how to fix these, i don't know why it said undefined could you please help me to solve this problems?

Message: Undefined index: nik

Filename: controllers/User.php

Line Number: 24

these are the code :

20    public function edit_profil()
21    {
22        $post = $this->input->post();
23        $data = [
24            'nik' => $post['nik'],
25            'nama' => $post['nama'],
26            'telp' => $post['telp'],
27            'divisi' => $post['divisi'],
28            'email' => $post['email'],
29            'username' => $post['username'],
30        ];

Solution

  • The $post variable doesn't contain, 'nik' key in it.

    Undefined index means that you array doesn't contain that 'key' in it.

    So please dump(var_dump($post) or print_r($post)) your $post variable first, to see what data comes.

    You can see the Controllers documentation here.

    And Request documentation here.