dongtao1262 2013-05-10 08:54
浏览 130

CI - 显示数据库错误或失败

I've developed a simple login system which works ok but fails, and I need to know why

QUESTION: How to show what is causing the fail. This is not a validation error but an error either with the data being passed to MySQL or the query somehow failing

here's the db function:

function login($email,$password)
{
    $this->db->where("email",$email);
    $this->db->where("password",$password);

    $query=$this->db->get("users");
    if($query->num_rows()>0)
    {
        foreach($query->result() as $rows)
        {
            //add all data to session
            $newdata = array(
                'user_id'  => $rows->id,
                'user_name'  => $rows->username,
                'user_email'    => $rows->email,
                'logged_in'  => TRUE,
            );
        }
        $this->session->set_userdata($newdata);
        return true;
    }
    return false;
}

And here's the logic:

public function login()
{
    $this->load->library('form_validation');
    // field name, error message, validation rules
    $this->form_validation->set_rules('email', 'Your Email', 'trim|required|valid_email');
    $this->form_validation->set_rules('password', 'Password', 'trim|required|min_length[4]|max_length[32]');

    if($this->form_validation->run() == FALSE)
    {
        $this->signin();
    }
    else
    {
        $email=$this->input->post('email');
        $password=md5($this->input->post('pass'));
        $result=$this->user_model->login($email,$password);
        if($result)
        {
            $this->dash();
        }
        else
        {
            $data['title']= 'Login Error';
            $this->load->view('nav/header', $data);
            $this->load->view('login', $data);
            $this->load->view('nav/footer', $data);
        }
    }
}

I know the error is happening as I redirect back to login page if fail and change title text to show me (only in testing mode for right now) - but how can I find out what is going wrong with the query?

  • 写回答

2条回答 默认 最新

  • donglu3087 2013-05-10 13:38
    关注

    You can use log_message and check the logs if the y behave as expected:

    http://ellislab.com/codeigniter/user-guide/general/errors.html

    I usually just use echo '<pre>'; print_r($query->result());die; just after the $query is formed. It's faster.

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题