• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
seegatesite header

Seegatesite.com

Seegatesite.com - Programming Tutorial , Sharing , How and Learn Together

  • TOOLS
    • Bootstrap Navbar Online Generator
    • Customize Sidebar Menu Bootstrap 3
    • Bootstrap Demo
  • ADVERTISE
  • CATEGORIES
    • Android
    • Blogging Tips
    • Database
    • CSS
    • Info Gadget
    • Javascript
    • Linux
    • PHP
    • Various
    • WordPress
  • Q&A
  • PHP
  • JAVASCRIPT
  • JQUERY
  • ANGULAR
  • WORDPRESS
  • SEO
  • REACT
🏠 » PHP » Connect Bootstrap Login Form and Mysql with PDO

Connect Bootstrap Login Form and Mysql with PDO

By Sigit Prasetya Nugroho ∙ November 10, 2014 ∙ PHP ∙ 2 Comments

Share : TwitterFacebookTelegramWhatsapp

bootstrap login form

Lately I playing around with the bootstrap framework. I will share how to create simple login form with bootstrap and connect it with mysql using PDO. Bootstrap has an elegant look. combined with ajax and jquery , will make your application run faster.

 Why we must use PDO to create connection with mysql ? 

PDO – PHP Data Objects – is a database access layer providing a uniform method of access to multiple databases.

PDO stands for PHP Data Objects which is a database access layer in PHP version 5.xx. In addition to having fast performance, PDO also supports a wide range of RDBMS including MySQL, CUBRID, MS SQL Server, Firebird, IBM, Informix, MS SQL Server, Oracle, ODBC and DB2, Postegre SQL, SQLite, and 4D. Just a reminder, to use PDO to connect to the database, you need to be a little familiar with OOP.

Related Articles :

  • Upgrade Responsive Bootstrap Table Using Footable Plugin
  • [Resolved] SweetAlert Prompt Not Working On Modal Dialog Bootstrap In Firefox
  • Change Bootstrap Modal Dialog Effect With Animate.css

Requirement :

Download AdminLTE Bootstrap template here

 Lets begin tutorial

1. Create Login form as php file (login.php)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
session_start();
?>
<!DOCTYPE html>
<html class="bg-black">
    <head>
        <meta charset="UTF-8">
        <title>Your title</title>
        <meta content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no' name='viewport'>
        <link href="css/bootstrap.min.css" rel="stylesheet" type="text/css" />
        <link href="font-awesome-4.1.0/css/font-awesome.min.css" rel="stylesheet" type="text/css" />
        <link href="css/AdminLTE.css" rel="stylesheet" type="text/css" />
        <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
        <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
        <!--[if lt IE 9]>
          <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
          <script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
        <![endif]-->
    </head>
    <body class="bg-black inverse">
        <div class="form-box" id="login-box">
            <div class="header">Login Form</div>
            <form action="validation.php" method="post">
                <div class="body bg-gray">
                    <div class="form-group">
                        <input type="text" name="username" required autofocus class="form-control" placeholder="Username"/>
                    </div>
                    <div class="form-group">
                        <input type="password" name="password" required class="form-control" placeholder="Password"/>
                    </div>
                </div>
                <div class="footer">
                    <button type="submit" class="btn bg-olive btn-block">Login</button>
                     <?php
if(isset($_GET['error']))
{
echo ' <div class="box-body"> <div class="callout callout-warning">';
if($_GET['error']==1)
{
echo "Please fill username or password.";
}
                                                                        if($_GET['error']==2)
{
echo "The username and password you entered did not match our records. Please double-check and try again.";
}
 
echo '</div></div>';
}
 
  ?>
                </div>
            </form>
        </div>
        <script src="js/jquery.min.js"></script>
        <script src="js/bootstrap.min.js" type="text/javascript"></script>
</body>
</html>

2. Create PDO class (pdo_db.php).

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<?php
class core_db extends PDO{
    private $engine;
    private $host;
    private $database;
    private $user;
    private $pass;
 
    private $result;    
 
    public function __construct()
        {
        $this->engine   = 'mysql';
        $this->host     = 'localhost';
        $this->database = 'yourdatabase';
        $this->user     = 'root';
        $this->pass     = '';
 
        $dns = $this->engine.':dbname='.$this->database.";host=".$this->host;
        parent::__construct( $dns, $this->user, $this->pass );
        }
}

3. Create validation form (validation.php)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php
session_start();
$username = $_POST['username'];
$password = $_POST['password'];
if (empty($username) && empty($password)) {
header('location:login.php?error=1');
break;
}
require_once('pdo_db.php');
try {
$database= new core_db;
$hasil=$database->prepare('select a.id_user,a.nama_user,a.level from t_user a where a.nama_user="'.$username.'" and a.pass_user='.$password);
$database->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$database->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$hasil->execute();
}
catch(Exception $e) {
    echo 'Exception -> ';
    var_dump($e->getMessage());
}
$jum=$hasil->rowCount();
if ($jum >=1)
{
while($data = $hasil->fetch(PDO::FETCH_ASSOC))
    {
$_SESSION['ses_nama_user'] = $data['nama_user'];
$_SESSION['ses_id'] = $data['id_user'];
$_SESSION['ses_level'] = $data['level'];
}
header('location:index.php');
}
else
{
header('location:login.php?error=2');
}
?>

Thus tutorials Connect Bootstrap Login Form and MySQL with PDO, please read my other bootstrap tutorial here

Another PHP Related Post :

  • Tutorial Create Simple POS Using ReactJS And Laravel Lumen Part 1
  • How To Replace String With Another String In PHP
  • Login Page – Tutorial CRUD Client and API Server Using JQuery And Lumen Part 2
  • Tutorial CRUD Client and API Server Using JQuery And Lumen Part 1
  • How To Solve Problems Illegal mix of collations (latin1_swedish_ci,IMPLICIT) In Laravel
  • How To Resolve No ‘Access-Control-Allow-Origin’ Header In Lumen

Avatar for Sigit Prasetya Nugroho

About Sigit Prasetya Nugroho

This site is a personal Blog of Sigit Prasetya Nugroho, a Desktop developer and freelance web developer working in PHP, MySQL, WordPress.

Reader Interactions

Comments

  1. Avatar for ali_belitiali_beliti says

    May 15, 2018 at 5:35 pm

    object not found. login_val.php ???

    Reply
    • Avatar for Sigit Prasetya NugrohoSigit Prasetya Nugroho says

      May 21, 2018 at 1:13 am

      sory, change login_val.php with validation.php

      thx 🙂

      Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Welcome to my Home,

Avatar for Sigit Prasetya NugrohoThis site is a personal Blog of Sigit Prasetya Nugroho, a Desktop developer and freelance web developer working in PHP, MySQL, WordPress.



Popular Articles

Checked checkbox AdminLTE Bootstrap in Jquery

November 4, 2014 By Sigit Prasetya Nugroho 7 Comments

Simple create date format validation with jqueryUI

December 21, 2014 By Sigit Prasetya Nugroho Leave a Comment

Create Simple Progress Bar for Fake Online Generator with Jquery

January 10, 2015 By Sigit Prasetya Nugroho Leave a Comment

22+ Coolest Free Jquery Plugin For Premium Theme

October 3, 2015 By Sigit Prasetya Nugroho Leave a Comment

Easy Build Your Anti Copy Paste Plugin

October 6, 2015 By Sigit Prasetya Nugroho Leave a Comment

Popular Tags

adminlte (15) adsense (13) adsense tips (4) affiliate amazon (13) amazon (12) Android (8) angular (16) angular 4 (12) angular 5 (4) asin grabber (3) Bootstrap (27) codeigniter (5) create wordpress theme (5) crud (8) css (6) free wordpress theme (7) google adsense (4) imacros (4) increase traffic (6) jquery (34) laravel (10) laravel 5 (5) learn android (5) lumen api (4) modal dialog (5) mysql (6) nodeJs (4) optimize seo (4) pdo (6) php (30) plugin (53) pos (8) Publisher Tips (5) react (6) Reactjs (9) SEO (37) theme (17) tutorial angular (5) tutorial angular 4 (6) tutorial javascript (10) tutorial javascript beginners (4) twitter (3) wordpress (18) wordpress plugin (13) XMLRPC (5)




  • About
  • Contact Us
  • Disclaimer
  • Privacy Policy
  • Terms and Conditions

©2022 Seegatesite.com