如果登录失败,那么如何重定向同一登录页面&显示错误的用户名 $('#login_form')。submit(function(e) { e.preventDefault(); var uname = $('#uname')。val(); var upassword = $('#upassword')。val(); if(uname ==“”|| upassword ==“”) { $('#errmessage')。show()。html('所有字段都是必需的'); } else { $( '#errmessage')HTML( “”),隐藏()。 $就({ 类型:“POST”, url:“User_controller / login_autho /”, 数据类型:'json', 数据:{uname:uname,upassword:upassword}, 成功:函数(数据){ $( '#successmessage')。淡入()。HTML(数据) window.location.replace( “/ User_controller /简档”); } }); } }); 要检查登录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 :(得分: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-> query('SELECT * FROM'your_table_name'WHER'uname'= $ uname AND'password'= $ upassword'); //查询根据您的要求修改
返回$ query-> count();
答案 1 :(得分: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";
}
}