Hi all okay so when i click on my home page on my login button it takes me to my login screen that all works well but when i submit the form it just reloads the page and does not redirect to the page specified in my controller. Also the error i want to display on the form does not work it gives me a parse error and i know that it is correct on the page.
Here is my controller
<?php defined('BASEPATH') OR exit('No direct script access allowed');
class Users extends CI_Controller
{
public function login()
{
$data['error'] = 0;
if ($_POST) {
$this->load->model('user');
$username = $this->input->post('username', true);
$password = $this->input->post('password', true);
$user = $this->user->login($username, $password);
if (!$user) {
$data['error'] = 1;
} else {
$this->session->set_userdata('userID', $user['userID']);
$this->session->set_userdata('username', $user['username']);
redirect(base_url().'site');
}
}
$data['title'] = "Login";
$data['content'] = 'login/login_view';
$this->load->view('templates/login/template', $data);
}
public function forgot_password(){
}
function logout(){
$this->session->sess_destroy();
redirect(base_url().'login');
}
}
Then my model contains the following code:
<?php defined('BASEPATH') OR exit('No direct script access allowed');
class User extends CI_Model
{
function create_user($data){
$this->db->insert('users',$data);
}
function login($username,$password){
$where = array(
'username' => $username,
'password' => sha1($password)
);
$this->db->select()->from('users')->where($where);
$query = $this->db->get();
return $query->first_row('array');
}
}
Then my view is structured like this:
<section id="login-landing" class="block block-gray">
<div class="container">
<div class="card card-container">
<a href="<?php echo base_url()?>">
<img id="profile-img" class="profile-img-card" src="<?php echo base_url();?>assets/img/site/main.png"
class="img-responsive">
</a>
<p id="profile-name" class="profile-name-card">Administrator Login</p>
<?php if($error == 1){ ?>
<p>The username / password did not match!</p>
<? } ?>
<form action="<?php echo base_url();?>users/login" method="post" class="form-signin">
<input type="text" id="username" class="form-control" placeholder="Username" autofocus>
<input type="password" id="password" class="form-control" placeholder="Password">
<input type="submit" class="btn btn-lg btn-primary btn-block btn-signin" value="Sign In">
</form><!-- /form -->
<a href="<?php echo base_url();?>users/forgot_password" class="forgot-password"> Forgot your password</a>
</div><!-- /card-container -->
</div><!-- /container -->
</section>
Please help me understand where i am going wrong here, thanks in advance