0

这来自一个登录表单,其中电子邮件和密码作为 to 字段:

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();

转到控制器进行表单验证:

$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);
    }

回调将其发送到:

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;
    }

}

当它调用 get_salt() 时,它会从模型中加载:

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';

    }

}

两天前同样的代码字很好,现在它给出了一个非对象错误:

$salt =  $row->salt;

不会正确加载查询,我使用 codeigniter 从 post 数组function $this->input->post('email')回显,它回显了正确的电子邮件。

但是当我print_r查询时它返回一个空的查询对象,但是电子邮件在用户数据库表中(在电子邮件字段和所有内容中),我已经检查过了,几天前我正在使用同一个帐户进行测试

4

1 回答 1

0

所以我收到了错误,因为我输入了错误的密码并且它确实测试了用户是否存在。

测试用户是否存在的代码:

CodeIgniter - Checking to see if a value already exists in the database

in the accepted answer

于 2012-12-15T20:08:32.710 回答