This is coming from a log in form with email and password as the to fields:
echo form_open('main/login_validation');
echo "<P>Email: </br>";
echo form_input('email',$this->input->post('email'));
echo "</P>";
echo "<P>Password: </br>";
echo form_password('password');
echo "</P>";
echo "<P>";
$img_path = base_url()."imgs/log_in_0.png";
echo '<input type="image" src="'.$img_path.'">';
echo "</P>";
echo form_close();
Goes to the controler for form validation:
$this->load->library('form_validation');
$this->form_validation->set_rules('email', 'Email', 'required|trim|xss_clean|callback_validate_credentials');
$this->form_validation->set_rules('password', 'Password', 'required|trim');
if($this->form_validation->run()){
$data = array(
'email' => $this->input->post('email'),
'is_logged_in' => 1
);
$this->session->set_userdata($data);
$nKey ='members';
$this->page($nKey);
} else {
$nKey ='login';
$this->page($nKey);
}
Callback sends it to:
public function validate_credentials(){
$this->load->model('model_users');
$salt = $this->model_users->get_salt();
if($this->model_users->can_log_in($salt)){
return true;
}else{
$this->form_validation->set_message('validate_credentials', 'Incorrect Email/Password.');
return false;
}
}
when it calls get_salt() it then loads from the model:
public function get_salt(){
$this->db->where('email', $this->input->post('email'));
$query = $this->db->get('users');
if($query){
$row = $query->row();
$salt = $row->salt;
return $salt;
}else{
echo 'failed salt';
}
}
this same code word fine two days ago, now it gives a non-object error on:
$salt = $row->salt;
Won’t load the query right, I echoed from the post array with codeigniter function $this->input->post('email'), and it echoed the correct email.
But when I print_r the query it comes back an empty query object, but the email is in the user db table (in the email field and everything), I have checked, I was using this same account to do tests just a few days ago
so i was getting the error because i entered the wrong pass word and it did test to see if the user existed.
code to test if user exist:
CodeIgniter – Checking to see if a value already exists in the database
in the accepted answer