-1

I just started coding so i dont know whats wrong with my code

A PHP Error was encountered

Severity: Notice

Message: Undefined variable: kd_user

Filename: views/dokter.php

Line Number: 1

Controller

function read_user()
{
    $this->load->model('dokter_model');
    $data['datauser']=$this->dokter_model->read_user();
    $this->load->view('dokter', $data);
}

Model

function read_user()
{
    $q="SELECT a.*, b.* 
        FROM users a 
        LEFT JOIN dokter b ON a.kd_user=b.kd_user
        WHERE a.kd_user='".$this->session->userdata('kd_user')."'";
    $query=$this->db->query($q);
    return $query->result();
}

Views

    <p align="center">Selamat Datang <?php echo $kd_user;?></p>

Sorry for my poor english

Ahmad
  • 41
  • 4

2 Answers2

0

Change :

$data['datauser']=$this->dokter_model->read_user();

to:

$data['kd_user']=$this->dokter_model->read_user();

Alex
  • 16,739
  • 1
  • 28
  • 51
0

In general, the error

Message: Undefined variable: kd_user

Means that you are referring to a variable (in this case, $kd_user), and it was never defined (you never initialized it and/or assigned a default value to it.)

Looking at your code, you are referring to kd_user in two places -- once in the associative array user_data in your model, and once in your view as kd_user.

To begin, you may wish to debug in each of those files (most probably the view) if that variable actually exists.

Without seeing all of your app's code, its hard to say for sure, but I'd verify that your view has a variable available called $kd_user for you to access. If it isn't there, you either need to find a way to get it into there, or reference another variable to get to the value you need.

Geremy
  • 2,415
  • 1
  • 23
  • 27