查询中有什么问题在codeigniter中出错了employee_id?

时间:2017-11-23 15:55:16

标签: php mysql codeigniter-3

我正在使用CI来实现我的项目。但我不明白我的查询中有什么错误,我错了employee_id。我正在写一个查询,其中我从db获得了一切正确,除了我的employee_id.i得到了一些其他employee_id。 我在很多表中都有employee_id。

我的疑问:

$this->db->select('*');
  $this->db->from('app_users');
  $where =  ' `USER_NAME` = "'.$username.'" '
            . 'AND SUBSTR(PASSWORD, '.($char1).', 1) = \''.$pass1.'\' '
            . 'AND SUBSTR(PASSWORD, '.($char2).', 1) = \''.$pass2.'\' ' 
            . 'AND SUBSTR(PASSWORD, '.($char3).', 1) = \''.$pass3.'\' '
            . 'AND SUBSTR(PIN, '.($char11).', 1) = \''.$pass4.'\' '
            . 'AND SUBSTR(PIN, '.($char22).', 1) = \''.$pass5.'\' '
            . 'AND SUBSTR(PIN, '.($char33).', 1) = \''.$pass6.'\' ';     
  $this->db->where($where);

     $this->db->join('employee_details', 'app_users.EMPLOYEE_ID = employee_details.EMPLOYEE_ID', 'LEFT');
     $this->db->join('employee_master', 'app_users.EMPLOYEE_ID = employee_master.EMPLOYEE_ID', 'LEFT');
     $this->db->join('designation_master', 'employee_details.DESIGNATION_ID = designation_master.DESIGNATION_ID', 'LEFT');
     $this->db->join('employee_visa_details', 'employee_details.EMPLOYEE_ID = employee_visa_details.EMPLOYEE_ID', 'LEFT');
     $this->db->join('visa_status_master', 'employee_visa_details.VISA_STATUS_ID = visa_status_master.VISA_STATUS_ID', 'LEFT');
     $this->db->join('employment_status_master', 'employee_details.EMPLOYMENT_STATUS_ID = employment_status_master.EMPLOYMENT_STATUS_ID', 'LEFT');             
     $this->db->join('employee_skills', 'employee_details.EMPLOYEE_ID = employee_skills.EMPLOYEE_SKILLS_ID', 'LEFT'); 

     $query = $this->db->get();

    return $query->result();

有时我在查询中遇到错误。

Error Number: 1064

You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ' 1) = '' AND SUBSTR(PASSWORD, , 1) = '' AND SUBSTR(PASSWORD, , 1) = '' AND SUBST' at line 10

SELECT * FROM `app_users` LEFT JOIN `employee_details` ON `app_users`.`EMPLOYEE_ID` = `employee_details`.`EMPLOYEE_ID` LEFT JOIN `employee_master` ON `app_users`.`EMPLOYEE_ID` = `employee_master`.`EMPLOYEE_ID` LEFT JOIN `designation_master` ON `employee_details`.`DESIGNATION_ID` = `designation_master`.`DESIGNATION_ID` LEFT JOIN `employee_visa_details` ON `employee_details`.`EMPLOYEE_ID` = `employee_visa_details`.`EMPLOYEE_ID` LEFT JOIN `visa_status_master` ON `employee_visa_details`.`VISA_STATUS_ID` = `visa_status_master`.`VISA_STATUS_ID` LEFT JOIN `employment_status_master` ON `employee_details`.`EMPLOYMENT_STATUS_ID` = `employment_status_master`.`EMPLOYMENT_STATUS_ID` LEFT JOIN `employee_skills` ON `employee_details`.`EMPLOYEE_ID` = `employee_skills`.`EMPLOYEE_SKILLS_ID` WHERE `USER_NAME` = "" AND SUBSTR(PASSWORD, , 1) = '' AND SUBSTR(PASSWORD, , 1) = '' AND SUBSTR(PASSWORD, , 1) = '' AND SUBSTR(PIN, , 1) = '' AND SUBSTR(PIN, , 1) = '' AND SUBSTR(PIN, , 1) = ''

Filename: C:/xampp/htdocs/CodeIgniter-3.1.6/system/database/DB_driver.php

Line Number: 691

我不知道我的查询有什么问题。因为我得到的所有其他数据都正确但employee_id不同。

这是我的控制器:

  $this->load->model('user_model');
        $username = $this->input->post('user_email');
        $pass1 = $this->input->post('pass1');
        $pass2 = $this->input->post('pass2');
        $pass3 = $this->input->post('pass3');

        $char1 = $this->input->post('char1');
        $char2 = $this->input->post('char2');
        $char3 = $this->input->post('char3');


        $pass4 = $this->input->post('pass4');
        $pass5 = $this->input->post('pass5');
        $pass6 = $this->input->post('pass6');

        $char11 = $this->input->post('char11');
        $char22 = $this->input->post('char22');
        $char33 = $this->input->post('char33');
        /*$password = $this->input->post('user_password');
        $pin = $this->input->post('user_pin');*/
        $is_valid = $this->user_model->validate($username,$char1,$pass1, $char2,$pass2, $char3,$pass3,$char11,$pass4,$char22, $pass5, $char33,$pass6);

请提前帮助我。谢谢。

0 个答案:

没有答案