Everytime I click the login submit button it goes to "Object not Found" error 404! I've been looking at my codes for hours and couldn't find the right solution. Please help! thanks!
每次我点击登录提交按钮,它都会转到“找不到对象”错误404!我一直在看我的代码几个小时,找不到合适的解决方案。请帮忙!谢谢!
login_controller.php
login_controller.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Login_controller extends CI_Controller {
public function index(){
$this->load->view('template/header');
$this->load->view('login_view');
echo "<script> alert('x'); </script>";
}
public function login(){
$email = $this->input->post('email');
$password = $this->input->post('password');
$successful = $this->login_model->login($email,$password);
if($successful){
$this->home();
} else {
echo "<script> alert('x'); </script>";
}
}
function home(){
if($this->session->userdata('email') != ""){
// $this->load->view('template/header');
// $this->load->view('home_view');
echo "<script> alert('y'); </script>";
} else {
// $this->load->view('template/header');
// $this->load->view('login_view');
echo "<script> alert('n'); </script>";
}
}
}
?>
login_view.php
login_view.php
<?php defined('BASEPATH') OR exit('No direct script access allowed'); ?>
<link href="<?php echo base_url(); ?>public/css/bootstrap.min.css" rel="stylesheet">
<link href="<?php echo base_url(); ?>public/css/custom.css" rel="stylesheet">
<div class="container">
<form class="form-login" method="post" action="login_controller/login">
<img src="<?php echo base_url(); ?>public/img/q_logo.png">
<label for="inputEmail" class="sr-only">Email address</label>
<input type="email" name="email" class="form-control" placeholder="Email address" required autofocus>
<label for="inputPassword" class="sr-only">Password</label>
<input type="password" name="password" class="form-control" placeholder="Password" required>
<button class="btn btn-lg btn-primary btn-block" type="submit">Log in</button>
</form>
</div>
login_model.php
login_model.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Login_model extends CI_Model {
function login($email,$password){
$this->db->where("email",$email);
$this->db->where("password",$password);
$query=$this->db->get("users");
if($query->num_rows()>0){
foreach($query->result() as $rows){
$newdata = array(
'email' =>$rows->email,
'firstname' =>$rows->firstname,
'lastname' =>$rows->lastname
);
}
$this->session->set_userdata($newdata);
return TRUE;
} else {
return FALSE;
}
}
}
?>
2 个解决方案
#1
2
Go application > config > config.php
转到application> config> config.php
Make sure that your base url is correctly entered, with /
at the end
确保正确输入基本网址,最后输入/
example: $config['base_url'] = 'http://192.168.7.123/admin/';
例如:$ config ['base_url'] ='http://192.168.7.123/admin/';
Note the /
at the end.
注意/最后。
I hope this helps :)
我希望这有帮助 :)
#2
0
Your code looks right. Your view exists? You entered the right name? I guess this your problem.
你的代码看起来正确。你的观点存在吗?你输入了正确的名字?我想这是你的问题。
And open your form tag using form_open().
并使用form_open()打开您的表单标记。
#1
2
Go application > config > config.php
转到application> config> config.php
Make sure that your base url is correctly entered, with /
at the end
确保正确输入基本网址,最后输入/
example: $config['base_url'] = 'http://192.168.7.123/admin/';
例如:$ config ['base_url'] ='http://192.168.7.123/admin/';
Note the /
at the end.
注意/最后。
I hope this helps :)
我希望这有帮助 :)
#2
0
Your code looks right. Your view exists? You entered the right name? I guess this your problem.
你的代码看起来正确。你的观点存在吗?你输入了正确的名字?我想这是你的问题。
And open your form tag using form_open().
并使用form_open()打开您的表单标记。