为什么我可以检测到无效的用户和密码,但是当我使用有效的用户和密码时,我收到了错误消息?

时间:2016-10-06 00:37:13

标签: php codeigniter frameworks

这是我的错误

  

发生数据库错误

     

错误号码:1064

     

您的SQL语法有错误;查看与您的MariaDB服务器版本对应的手册,以获得正确的语法,以便在“" SET`_ last_activity` = 1475713773,`user_data` =' a:2:{s:9:\" USER_DATA \&#34 ;; S:0:\" \"'在第1行

     

UPDATE SET`last_activity` = 1475713773,`user_data` =' a:2:{s:9:\" user_data \&#34 ;; s:0:\" \ &#34 ;; S:6:\"用户ID \&#34 ;; S:1:\" 1 \&#34 ;;}'在哪里`session_id` =' 738744d19c2e9e582af4afb59826e331'

     

文件名:C:/xampp/htdocs/CI3/system/database/DB_driver.php

     

行号:691

这是我的控制者:

function login(){
    $data['error']=0;
    if($_POST){
        $this->load->model('user');
        $username=$this->input->post('username',true);
        $password=$this->input->post('password',true);
        $user=$this->user->login($username,$password);
        if(!$user){
            $data['error']=1;
        } else {
            $this->session->set_userdata('userID',$user['userID']);
            //$this->session->set_userdata('user_type',$user['user_type']);
            redirect(base_url().'posts');
        }
    }

    $this->load->view('header');
    $this->load->view('login',$data);
    $this->load->view('footer'); 
}

这是我的模特:

function login($username,$password){
    $where=array(
        'username'=>$username,
        'password'=>$password
        );
    $this->db->select()->from('users')->where($where);
    $query=$this->db->get();
    return $query->row_array('array');
}

我的问题是我可以检测到无效的用户名和密码,但如果我使用有效的用户名和密码,则会出现上述错误。

1 个答案:

答案 0 :(得分:0)

注意到代码中存在多个错误。将模型修改为(<div id="response_wrapper"> <div id="timer_response"></div> <div id="remaining_response"></div> </div> repeatAjax(); function repeatAjax(){ $.ajax({ type: "GET", url: "get_feed.php", dataType: "html", success: function(response, status) { $("#remaining_response").html(response); }, complete: function() { setTimeout(repeatAjax,3000);//comment this line of code if you want to prevent further refreshing of image and username } }); }; repeatAjax2(); function repeatAjax2(){ $.ajax({ type: "GET", url: "get_feed.php?&tm=true", dataType: "html", success: function(response, status) { $("#timer_response").html(response); }, complete: function() { setTimeout(repeatAjax2,1000); } }); }; select()问题)

row_array()

最后确保你的`ci_sessions&#39;表格创建为

function login($username,$password){
    $where = array(
        'username'=>$username,
        'password'=>$password
        );
    $this->db->select('*')->from('users')->where($where);
    $query=$this->db->get();
    return $query->row_array();
}

看到这不是CREATE TABLE IF NOT EXISTS `ci_sessions` ( `id` varchar(40) NOT NULL, `ip_address` varchar(45) NOT NULL, `timestamp` int(10) unsigned DEFAULT 0 NOT NULL, `data` blob NOT NULL, KEY `ci_sessions_timestamp` (`timestamp`) ); 而是session_id