我尝试在Codeigniter中开发一个登录系统,但出于某种原因,当表单被提交并显示ERROR LOADING PAGE时。我试图在表单中的action =“”上找到很多可能性,但它总是给我同样的错误。有人可以帮我吗?
我的代码如下:
我的观点signIn.php
<?php include("includes/header.php"); ?>
<body>
<div id="login" data-role="page" class="outpage">
<div data-role="header"><h1>login</h1></div>
<div class="confpage" style="text-align:center;">
<img src="<?php echo base_url() ?>template/images/logomarca.jpg" />
<form action="user/login" method="post">
<input type="text" placeholder="Email" name="email" id="email">
<input type="password" placeholder="Password" name="password" id="password">
<button class="buttonDefault" type="submit" name="submit" id="submit">Login</button>
</form>
<a data-transition="slide" href="<?php echo base_url(); ?>">Back</a>
</div>
</div>
</body>
我的控制器user.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class User extends CI_Controller{
public function __construct(){
parent::__construct();
$this->load->model('user_model');
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
}
public function signIn(){
$this->load->view('signIn');
}
public function login(){
$this->form_validation->set_rules('email', 'Email', 'trim|required');
$this->form_validation->set_rules('password', 'Password', 'trim|required|callback_check_database');
if($this->form_validation->run() == FALSE){
$this->load->view('signUp');
}else{
$this->load->view('admin/admin');
}
}
function check_database($password){
//Field validation succeeded. Validate against database
$email = $this->input->post('email');
//query the database
$result = $this->user->login($email, $password);
if($result) {
$sess_array = array();
foreach($result as $row){
$_SESSION['id'] = $row->id;
$_SESSION['fname'] = $row->fname;
$sess_array = array(
'id' => $row->id,
'fname' => $row->fname);
$this->session->set_userdata('logged_in', $sess_array);
}
return TRUE;
}
else
{
$this->form_validation->set_message('check_database', 'Invalid email or password');
return false;
}
}
}
那就是我的模型user_model.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class User_model extends CI_Model{
public function __contruct(){
parent::__contruct();
}
public function signUp($data){
$this->db->insert('users', $data);
}
public function login($email, $password) {
$password = md5($password);
$this -> db -> select('id, fname, lname, password');
$this -> db -> from('users');
$this -> db -> where('email', $email);
$this -> db -> where('password', $password);
$this -> db -> limit(1);
$query = $this -> db -> get();
if($query -> num_rows() == 1) {
return $query->result();
}else {
return false;
}
}
}