我已经建立了登录系统,但是当我点击"登录"我收到此错误消息: "错误404找不到对象"。
我现在不知道该做什么:S。
这是我的代码:
我的登录文件(带按钮的主文件)
<!DOCTYPE html>
<html lang="">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>WELCOME! » Jaranguda.com</title>
<link rel="stylesheet" href="https://netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<h3>Login</h3>
<hr>
<form action="<?php echo base_url('Login/user')?>" method="POST">
<div class="form-group">
<label for="cari">USERNAME</label>
<input type="text" name="usuario" id="usuario" class="form-control">
</div>
<div class="form-group">
<label for="cari">PASSWORD</label>
<input type="password" name="contrasena" id="contrasena" class="form-control">
</div>
<input class="btn btn-primary" type="submit" value="Login">
<input class="btn btn-primary" type="reset" value="Reset">
</form>
</div>
</body>
控制器文件:
<?php
class Login extends CI_Controller{
public function __construct(){
parent::__construct();
$this->load->model("Login_model");
}
public function index(){
$this->load->view("login");
}
public function user(){
$data['login']=$this->Login_model->login();
$this->load->view('user', $data);
}
}
?>
模型文件:
<?php
class Login_model extends CI_Model{
public function __construct(){
$this->load->database();
}
public function login(){
$usuario=$this->input->POST('usuario', TRUE);
$contrasena=md5($this->input->POST('contrasena', TRUE));
$data=$this->db->query("SELECT * from usuarios where usuario=$usuario and contrasena=$contrasena LIMIT 1");
return $data=row();
}
}
?>
用户文件:
<!DOCTYPE html>
<html lang="">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>BIENVENIDO! » Jaranguda.com</title>
<link rel="stylesheet" href="https://netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js">
</script>
</head>
<body>
<div class="container">
<h3>Login</h3>
<hr>
<?php
if(count($login)>0)
{
if($login->tipo=='0')
echo "<p>YOU LOGGED AS: <b>".$login->tipo."</p>"
}
elseif($login->tipo =='1'){
echo "<p>usuario <b>".$login->usuario."</b> LOGGED AS: <b>".$login->tipo."</p>"
}
else{
echo "<p>usuario <b>".$login->usuario."</b> SOMETHING WENT WRONG WHILE LOGGING</p>"
}
?>
<?php
}
else
{
echo "<p>USERNAME/PASSWORD INVALID.</p>"
}
?>
</div>
<script src="//code.jquery.com/jquery.js"></script>
<script src="//netdna.bootstrapcdn.com/bootstrap/3.0.3/js/bootstrap.min.js"></script>
</body>
</html>
希望你能帮助我:S
答案 0 :(得分:0)
您的登录方法 应在Login_model
返回:
return $data->row();
不:
return $data = row();
您需要将用户信息传递到您的模式:
这两行应该在你的控制器中:
public function user(){
$usuario=$this->input->post('usuario', TRUE);
$contrasena=md5($this->input->post('contrasena', TRUE));
$data['login']=$this->Login_model->login($usuario, $contrasena);
$this->load->view('user', $data);
}
和模型:
public function login($usuario, $contrasena) {
$this->db->where('usuario',$usuario);
$this->db->where('contrasena',$contrasena);
$query = $this->db->get("your_table_name");
return $query->row_array();
}
答案 1 :(得分:0)