1

请帮我处理这段代码,这里是登录模型的代码(mlogin.php)

<?php if(! defined('BASEPATH')) exit (" No direct script access allowed");

class Mlogin extends CI_Model{

public function cek_db(){

    $this->db->where('id_user', $this->input->post('username'));
    $this->db->where('password', $this->input->post('pass'));
    $query = $this->db->get('user');

    if($query->num_rows == 1){
        RETURN true;
    } 
} 

function cek_page(){
    $uname = $this->input->post('username');

    $jenis_user = $this->db->select("`jenis_user` FROM `user` WHERE id_user = '".$uname."' ");


    if($jenis_user == 'member'){
           RETURN "1";
    }else if($jenis_user == 'agen komunitas'){
           RETURN "2"; 
    }else if($jenis_user == 'agen non-komunitas'){
           RETURN "3";
    }else{
           RETURN null;
    }
}
}

?>

这是登录控制器

<?php if(! defined('BASEPATH')) exit('No direct script access allowed');

class Login_control extends CI_Controller{

public function cek_user() {

    $this->load->model('mlogin');
    $query = $this->mlogin->cek_db();
    if($query){
        RETURN 'yes';
    }else{
        RETURN 'no';
    }
}

public function user_masuk() {
   if($this->cek_user() == 'yes'){
       $data['id_user'] = $this->input->post('username');
       $data['password'] = $this->input->post('pass');           

       $this->load->model('mlogin');
       $ju = $this->mlogin->cek_page();

       $data_session = array('id_user'=> $data['id_user'], 'jenis_user' => $ju);
       $this->session->set_userdata($data_session);

       if($ju == '1'){
           $this->load->view('welcome_message1');
       }else if($ju == '2'){
           $this->load->view('welcome_message2');    
       }else if($ju == '3'){
           $this->load->view('welcome_message3');
       }else{
           //ERROR
           echo "ERROR";
       } 

   }else if($this->cek_user() == 'no'){
        echo "Anda belum terdaftar menjadi MEMBER / AGEN";
   }else{
       echo"LOGIN GAGAL....";
   }


}


public function logout(){
    $this->session->sess_destroy();
    redirect('view/index');
    echo "anda telah berhasil logout";
 }

}

?>

结果总是“错误”

4

0 回答 0