用户
 找回密码
 入住 CI 中国社区
搜索
查看: 1066|回复: 2
收起左侧

[HELP] 想做一个简单的登录功能

[复制链接]
发表于 2016-1-7 15:19:31 | 显示全部楼层 |阅读模式
现在数据库插入帐号密码,然后界面登录,验证成功后就跳转页面,可是代码不知道哪来错了
控制器:
public function login_info_view()
    {
        $this->load->model('information_model');
        $user = $this->db->get('user');
        $data['user'] = $this->information_model->get_user();
        $login_account = $this->input->post('account');
        $login_password = $this->input->post('password');//输入的帐密
        $this->form_validation->set_rules('Account', 'Account', 'required');
        $this->form_validation->set_rules('Password', 'Password', 'required');
        if ($this->input->post()==NULL)
        {
            $this->load->view('information/login_info_view',$data);
        }
        else
        {   if($this->form_validation->run())
            {
                $this->load->view('information/Success');
            }
            else $this->load->view('information/Fail');
        }

    }

模型
        public function get_user()
        {
                $all_user = $this->db->get('user');
                $data = array(
                'account' => $this->input->post('account'),
                'password'=>$this->input->post('password'),
            );
            $sql = $this->db->query("select * from  user WHERE account = 'account' AND password = 'password'");
            return $all_user->result_array();
        }

有大神可以帮我改一下吗。。
发表于 2016-1-7 16:09:26 | 显示全部楼层
$user = $this->db->get('user');这一行是要获得模型的返回结果,其一,获得了结果程序里也没有利用,其二,模型里返回的结果只是全表的数组。程序根本没有验证用户名和密码
发表于 2016-1-7 16:10:21 | 显示全部楼层
$this->form_validation->run()这个是验证规则,不是验证用户名和密码

本版积分规则