CRUD Admin-Panel with Bootstrap, PHP & MySQL Part-4 (Update-Data)
Following code examine on how to create an admin-panel & CRUD (Create, Read, Update, Delete) web application using Bootstrap, PHP & MySQL. Part-4 focus on Update-Data.
- In above Update-Data page 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");
}
?>
-
In above Update-Data page consist of
<?php echo ($user); ?>
, which shows the login admin user-name derived from “role-admin.php”. -
In above Update-Data page contain a link to “inlog-logout.php” which end the session and redirect to “index.php”. “inlog-logout.php” code cast as below:
<?php
session_start();
session_destroy();
header('location:index.php');
?>
- In above Update-Data page below code snippet written to post the collected form data into “panel-admin-edit-on.php”.
<?php
if(isset($_POST["contact_email"]))
{
include('panel-admin-edit-on.php');
}
?>
- “panel-admin-edit-on.php” code cast as below:
<?php
$contact_name=$_POST["contact_name"];
$contact_email=$_POST["contact_email"];
$contact_message=$_POST["contact_message"];
$con=mysqli_connect("localhost","root") or die ("<div class=\"row\"><div class=\"span2\"></div>
<div class=\"span3 offset\"><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 offset\"><div class=\"alert-block\">
<a href=\"\" class=\"close\" data-dismiss=\"alert\">×</a>
<strong>Error !</strong> Database Can't Access !
</div></div></div>");
$sql="UPDATE contact SET name='$contact_name', message='$contact_message' WHERE email='$contact_email'";
$query=mysqli_query($con,$sql) or die ("<div class=\"row\"><div class=\"span3 offset\"><div class=\"alert-block\">
<a href=\"\" class=\"close\" data-dismiss=\"alert\">×</a>
<strong>Error !</strong> Check SQL Statement !
</div></div></div>");
if($query>0)
{
echo ("<div class=\"row\"><div class=\"span3 offset\"><div class=\"alert-block\">
<a href=\"\" class=\"close\" data-dismiss=\"alert\">×</a>
<strong>Success !</strong> Update Message Request Complete !
</div></div></div>");
}
else
{
echo ("<div class=\"row\"><div class=\"span3 offset\"><div class=\"alert-block\">
<a href=\"\" class=\"close\" data-dismiss=\"alert\">×</a>
<strong>Error !</strong> Update Request Cannot Send ! No Database Connectivity !
</div></div></div>");
}
mysqli_close($con);
?>
- Once the above code execute if functions and statements are true with verification of the database, it will move forward to Update-Data if not error messages shown. Update-Data page interface will cast as in below figure:
Now you have implement CRUD Update-Data function. 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)