if I do not fill in the username or username is not in the database then it will be error Trying to get property 'password' of non-object
Filename: controllers/user.php
Line Number: 74`
my code controller/user
public function login(){
$this->load->library('form_validation');
$input = $this->input->post(NULL, TRUE);
$this->username_temp = @$input['username'];
if($this->form_validation->run('login') == FALSE){
$this->load->view('form_login');
}
else{
$this->load->library('session');
$login_data = array(
'username' => $input['username'],
'login_status' => TRUE
);
$this->session->set_userdata($login_data);
redirect(base_url('depan/index'));
}
}
public function password_check($str){
$this->load->model('user_model');
$user_detail = $this->user_model->get_user_detail($this->username_temp);
if($user_detail){
if($user_detail->password == crypt($str,$user_detail->password)){
return TRUE;
}
else{
$this->form_validation->set_message('password_check', 'Password
yang anda masukan salah');
return FALSE;
}
}
else{
$this->form_validation->set_message('password_check', 'Username
yanga anda masukan ');
return FALSE;
}
}
my code form validation in config
'login' => array(
array('field' => 'username',
'label' => 'username',
'rules' => 'required'
),
array( 'field' => 'password',
'label' => 'password',
'rules' => 'required|callback_password_check'
)
)
my code form_login
<h1>Login</h1>
<?php echo validation_errors(); ?>
<form action="<?php echo base_url('user/login'); ?>" method="POST">
<label>Username</label><input type="text" name="username" /><br />
<label>Password</label><input type="password" name="password" /><br />
<input type="submit" name="submit" value="Login" />
my user_detail in model
public function get_user_detail($username){
$this->db->where("username", $username);
$query = $this->db->get('register');
if($query->num_rows() > 0){
$data = $query->row();`enter code here`
$query->free_result();
}
else{
$data = NULL;
}
return $data;
}
why if I do not fill the username in the form will error?
Message: Trying to get property 'password' of non-object
Filename: controllers/user.php
Line Number: 74
Backtrace:
File: D:\XAMPP\htdocs\ilmu\ilmusepuluh\application\controllers\user.php Line: 74 Function: _error_handler
line number 74 is
$this->form_validation->set_message('password_check', 'Password yang anda masukan salah');
password
is used as a property isif($user_detail->password == crypt($str,$user_detail->password)){
Is that line 74? If not, what is the code of line 74? – DFriendusername
asrequired
so you should get aThe username field is required.
Irregardless, I ran your same code on my platform and wasn't able to replicate the error. – Alex