Simple Login Form in CodeIgniter, MySQL and Bootstrap

By | January 4, 2017

In this tutorial we will see simple Login form in CodeIgniter, MySQL and bootstrap. CodeIgniter is a very popular PHP framework. We have also covered a nice CodeIgniter tutorial for beginners. We had previously covered simple login system with CodeIgniter however today we will share using Twitter Bootstrap. We have improved our UI thanks to inbuild classes in Bootstrap.

login form in codeigniter



Simple Login Form in CodeIgniter, MySQL and Bootstrap

CodeIgniter Login Form Tutorial


CREATE DATABASE `codeigniter_insert` ;

`id` int(10) AUTO INCREMENT,
`email` varchar(55) NOT NULL,
`password` varchar(55) NOT NULL
) ;

login_view.php (View)

In this file we will input email and password. When we will click on login we will make request to Login controller and call chk_login() function. The function checks if email id and password exists. If the user exists then User will be able to login successfully.

If the user click on logout the session will be destroyed.

<!DOCTYPE html>

<link rel="stylesheet" href="">

<script src=""></script>

<script src=""></script>



position: absolute;
width: 220px;
padding: 10px;
border: 3px solid green;
margin: 1;




<nav class="navbar navbar-default">

<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->

<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<a class="navbar-brand" href="#">TechPlugg Dashboard</a>

<ul class="nav navbar-nav navbar-right">


<!-- /.navbar-collapse -->

<!-- /.container-fluid -->


<h1>Welcome to TechPlugg</h1>

We are a Tech Blog with Programming tutorials

<form enctype="multipart/form-data" action="<?php echo base_url(); ?>index.php/Login/chk_login" method="post" >
<div id ="main">

<input type="text" name="email" placeholder="Enter your Email ID" /><br/><br/><br/>
<input type="password" name="password" placeholder="Enter a password"/><br/><br/><br/>

<center><input type="submit" value="Login" class="btn btn-primary"/></center>

Login.php (Controller)

We have two functions chk_login() and logout(). Chk_login() simply checks if email id and password exists in the database.

class Login extends CI_Controller {

 function __construct()
 $this->load->helper(array('form', 'url'));

 //index function
 function index()
 //load file upload form

 function chk_login()

 $email = $this->input->post('email');
 $password = md5(trim($this->input->post('password')));
 if($email !='' && $password!='')

 $query = "select * from login where email = '" . $email . "' and password = '" . $password . "'";
 $res = $this->db->query($query);
 $count = $res->num_rows();
 $sessiondata = array(
 'email' => $email,
 'user_login' => TRUE
 $this->load->view('success_login', $sessiondata);
 echo "Incorrect Email or password";
 function logout()


success_view.php (View)

echo "Login Successful";


<a href="<?php echo base_url(); ?>index.php/Login/logout">Logout</a>


So this was simple Login form in CodeIgniter, MySQL and bootstrap. If you like this tutorial please share it with your friends. Do let me know any doubts in comments.