2016-05-26 76 views
0

如果登錄失敗則如何重定向相同的登錄頁面&顯示錯誤的用戶名 $(「#login_form」)提交(函數(E) { e.preventDefault() ; var uname = $('#uname')。val(); var upassword = $('#upassword')。val(); if(uname ==「」|| upassword ==「」) {('#errmessage').show().html('All Fields are required'); } else {('#errmessage').html(「」)。hide(); $。阿賈克斯({ 類型: 「POST」, URL: 「User_controller/login_autho /」, 數據類型: 'JSON', 數據:{UNAME:UNAME,upassword:upassword}, 成功:功能(數據){ $('# ()/ user_controller/profile「); } }); } }); 要檢查登錄autho,如果成功,然後重定向到的個人資料頁笨:如何檢查用戶名和密碼

public function login_autho() { 
       $data = array(
        'uname' => $this->input->post('uname'), 
        'upassword' => $this->input->post('upassword') 
       ); 

       $result = $this->login_model->login_user($data); 

       if ($result == TRUE) { 
        $this->session->set_flashdata('success', 'Success Login'); 
        $this->load->view('user/success'); 
       // echo 'su'; 
       } else { 
        //$this->session->set_flashdata('error', 'Invalid Username or Password'); 
        //echo 'invalid user'; 
       // echo json_encode(false); 
        } 
      } 

      public function profile() { 
       $this->load->view('header'); 
       $this->load->view('user/success'); 
      } 

回答

0

簡單的

$uname = $this->input->post('uname'); 
    $upassword = $this->input->post('upassword'); 

寫通過這些變量模型函數

$this->Model->login($uname,$upassword); // Login method you have to create 

if($query->count() ==1 ){ 
    echo 'login'; 
    }else{ 
    echo "failed"; 
    } 

然後在數據庫

檢查

$ query = $ this-> db->查詢('SELECT * FROM'your_table_name'WHERE'uname'= $ uname AND'password'= $ upassword'); //查詢按照你的要求修改

return $ query-> count();

0

控制器

$uname = $this->input->post('uname'); 
    $upassword = $this->input->post('upassword'); 
    $result= $this->Model->login($uname,$upassword); // Login method you have to create 
    if($result=='login'){ 
     header('location:dashbord.php'); 
    } else { 
     header('location:index.php?error=1'); 
    } 

模態

public function login($uname,$upassword){ 
    $query = $this->db->query('SELECT * FROM 'your_table_name' WHERE uname='. $uname. ' AND password='. $upassword); // Query modify as per ur requirement 

    if(count($query) ==1 ){ 
     echo 'login'; 
     }else{ 
     echo "failed"; 
     } 

}