How to make Login page for admin-panel using PHP and Mysql.(Dynamic web page)

Step 1

Create table in mysql.
Table structure is as follow:

CREATE TABLE IF NOT EXISTS `logindetails` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `loginid` varchar(20) NOT NULL,
  `password` varchar(20) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=1;


Step 2

Html code
  <div class="row">
        <div class="well col-md-5 center login-box">

<h2>Welcome to (Admin Panel)</h2>
            <div class="alert alert-info">


                Please login with your Username and Password.
            </div>
            <form class="form-horizontal" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" id="defaultForm" enctype="multipart/form-data">
                                 <div class="input-group input-group-lg">
                        <span class="input-group-addon"><i class="glyphicon glyphicon-user red"></i></span>
                        <input type="text" class="form-control" placeholder="Username" name="username" id="username" data-toggle="tooltip" title="Please give your Name." rel="txtTooltip"  data-placement="top">
                    </div>
               
                    <div class="clearfix"></div><br>

                    <div class="input-group input-group-lg">
                        <span class="input-group-addon"><i class="glyphicon glyphicon-lock red"></i></span>
                        <input type="password" class="form-control"  name="password1" data-toggle="tooltip" title="Please give Password." rel="txtTooltip"  data-placement="top" id="password1" placeholder="Password">
                    </div>
                    <div class="clearfix"></div>

                    <div class="input-prepend">
                        <label class="remember" for="remember"><input type="checkbox" id="remember"> Remember me</label>
                    </div>
                    <div class="clearfix"></div>

                    <p class="center col-md-5">
                        <button type="submit" class="btn btn-primary" name="submit">Login</button>
                    </p>
         
            </form>
        </div>
        <!--/span-->
    </div><!--/row-->
</div><!--/fluid-row-->

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

Step 3

Php script which connect HTML with MYSQL for login and password  check from database.


ob_start();

$_SESSION["username"]=$_POST["username"];

$message="";

if(count($_POST)>0)

{

//include 'include/config.php';

$result = mysql_query("SELECT * FROM logindetails WHERE loginid='" . $_POST["username"] . "' and password = '". $_POST["password1"]."'");

$row  = mysql_fetch_array($result);

if(is_array($row)) {

$_SESSION["username"] = $row[loginid];

$_SESSION["password"] = $row[password];
$_SESSION['authorized'] = true;
//echo $_SESSION["username"];



} else

{

//$message = "Invalid Username or Password!";

$_SESSION['error'] = 'Sorry, wrong username or password';

}

}

if(isset($_SESSION["username"]))

{

header('Location: admin.php');

Comments

Popular posts from this blog

What is HTML? Complete Beginner’s Guide (with Examples)

HTML Forms — Input, Label, Button & Validation (Explained Like a Teacher With Examples)

Difference Between HTML and HTML5 (2025 Explained) | Features, Advantages & Comparison Table