CRUD Admin-Panel with Bootstrap, PHP & MySQL Part-1 (Admin-Panel)
Following code examine on how to create an admin-panel & CRUD (Create, Read, Update, Delete) web application using Bootstrap, PHP & MySQL. Part-1 focus on Admin-Panel.
Below represent the CRUD Admin-Panel Hierarchy Diagram:
Note: Hierarchy Diagram is an architectural diagram, which represent the structured design of the system using simple notations. This is a useful diagram to understand the dynamic structure of a system.
- Bootstrap integrated PHP Admin-Panel login page code cast as below:
- Below code snippet written to determine whether the admin role is set or not. [Inside of “index.php”]
<?php
session_start();
if(isset($_SESSION['role']))
{
header("location:inlog-navigate-role.php");
}
?>
- Below code snippet written to post the collected form-data. [Inside of “index.php”]
<?php
if(isset($_POST["user_name"]))
{
include('inlog-log.php');
}
?>
- Bootstrap integrated PHP Admin-Panel login page interface cast as below:
- For secure purpose “inlog-log.php” include only below code.
<?php
include('inlog-loger.php');
?>
- Below code “inlog-loger.php” function as a validation between form-data and database, in according to verification it will move forward or show relevant messages.
<?php
if(isset($_SESSION['role']))
{
include('inlog-navigate.php');
}
$username=$_POST["user_name"];
$password=$_POST["password"];
$con=mysqli_connect("localhost","root") or die ("<div class=\"row\"><div class=\"span2\"></div>
<div class=\"span3\"><div class=\"alert-block\">
<a href=\"\" class=\"close\" data-dismiss=\"alert\">×</a>
<strong>Error !</strong> Server Can't Access !
</div>
</div></div>");
$db=mysqli_select_db($con,"dbnew2") or die ("<div class=\"row\"><div class=\"span2\"></div>
<div class=\"span3\"><div class=\"alert-block\">
<a href=\"\" class=\"close\" data-dismiss=\"alert\">×</a>
<strong>Error !</strong> Database Can't Access !
</div>
</div></div>");
$sql="SELECT * FROM login WHERE rolename='$username' and password='$password'";
$query=mysqli_query($con,$sql) or die ("<div class=\"row\"><div class=\"span2\"></div>
<div class=\"span3\"><div class=\"alert-block\">
<a href=\"\" class=\"close\" data-dismiss=\"alert\">×</a>
<strong>Error !</strong> Check SQL Statement !
</div>
</div></div>");
if(mysqli_affected_rows($con)>0)
{
$row = mysqli_fetch_array($query);
$_SESSION['username'] = $row['rolename'];
$_SESSION['role'] = $row['role'];
include('inlog-navigate.php');
}
else
{
include('inlog-error.html');
}
mysqli_close($con);
?>
- Once the above code execute if functions and statements are true with verification of the database, it will move to “inlog-navigate.php” if not show message as in “inlog-error.html”.
<?php
$role = $_SESSION['role'];
if($role=='admin')
{
header("location:panel-admin-detail.php");
}
else
{
include('inlog-error-role.html');
session_destroy();
}
?>
- As mention in previous code “inlog-navigate.php” while log-into system if role session is not set this message will appear “inlog-error-role.html”.
- Below code “inlog-navigate-role.php” determine to start the role session if the prefer database login-info is matched with entered login-info, this will lead to CURD Admin-Panel. If not this message will appear “inlog-error-in.html”.
<?php
session_start();
$role = $_SESSION['role'];
if($role=='admin')
{
header("location:panel-admin-detail.php");
}
else
{
header("location:inlog-error-in.html");
session_destroy();
}
?>
- Once log-into CURD Admin-Panel, following pages “panel-admin-add.php”, “panel-admin-detail.php”, “panel-admin-edit.php”, and “panel-admin-remove.php” are consist of
<? php include('role-admin.php'); ?>
which seek if the login user is an authorized admin, if not it will redirect to “index.php”. “role-admin.php” code cast as below:
<?php
session_start();
$user = $_SESSION['username'];
if(isset($_SESSION['role']))
{
if($_SESSION['role']!='admin')
{
header("location:index.php");
}
}
else
{
header("location:index.php");
}
?>
- With proper user-name and password will log-into CURD Admin-Panel, login admin user-name will show as in below figure:
Now you have created an Admin-Panel and log-into it. For further development of CRUD Admin-Panel Web-Application read the below articles.
CRUD Admin-Panel with Bootstrap, PHP & MySQL Part-1 (Admin-Panel)
CRUD Admin-Panel with Bootstrap, PHP & MySQL Part-2 (Create-Data)
CRUD Admin-Panel with Bootstrap, PHP & MySQL Part-3 (Read-Data)
CRUD Admin-Panel with Bootstrap, PHP & MySQL Part-4 (Update-Data)
CRUD Admin-Panel with Bootstrap, PHP & MySQL Part-5 (Delete-Data)
CRUD Admin-Panel with Bootstrap, PHP & MySQL Part-6 (Database-Implementation)