Step 4 Creation of Add/Manage Book Module
This is how Add/Manage Books will look like:
Features:
- Admin can add a new book using its details.
- Admin can edit the details of existing books.
- All changes will be reflected on our SQL database.
Code:
Below is the code for modules mentioned above:
<?php
require("functions.php");
session_start();
#fetch data from database
$connection = mysqli_connect("localhost","root","");
$db = mysqli_select_db($connection,"lms");
$name = "";
$email = "";
$mobile = "";
$query = "select * from admins where email = '$_SESSION[email]'";
$query_run = mysqli_query($connection,$query);
while ($row = mysqli_fetch_assoc($query_run)){
$name = $row['name'];
$email = $row['email'];
$mobile = $row['mobile'];
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Add New Book</title>
<meta charset="utf-8" name="viewport" content="width=device-width,intial-scale=1">
<link rel="stylesheet" type="text/css" href="../bootstrap-4.4.1/css/bootstrap.min.css">
<script type="text/javascript" src="../bootstrap-4.4.1/js/juqery_latest.js"></script>
<script type="text/javascript" src="../bootstrap-4.4.1/js/bootstrap.min.js"></script>
<script type="text/javascript">
function alertMsg(){
alert(Book added successfully...);
window.location.href = "admin_dashboard.php";
}
</script>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="admin_dashboard.php">Library Management System (LMS)</a>
</div>
<font style="color: white"><span><strong>Welcome: <?php echo $_SESSION['name'];?></strong></span></font>
<font style="color: white"><span><strong>Email: <?php echo $_SESSION['email'];?></strong></font>
<ul class="nav navbar-nav navbar-right">
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" data-toggle="dropdown">My Profile </a>
<div class="dropdown-menu">
<a class="dropdown-item" href="">View Profile</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#">Edit Profile</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="change_password.php">Change Password</a>
</div>
</li>
<li class="nav-item">
<a class="nav-link" href="../logout.php">Logout</a>
</li>
</ul>
</div>
</nav><br>
<nav class="navbar navbar-expand-lg navbar-light" style="background-color: #e3f2fd">
<div class="container-fluid">
<ul class="nav navbar-nav navbar-center">
<li class="nav-item">
<a class="nav-link" href="admin_dashboard.php">Dashboard</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" data-toggle="dropdown">Books </a>
<div class="dropdown-menu">
<a class="dropdown-item" href="add_book.php">Add New Book</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="manage_book.php">Manage Books</a>
</div>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" data-toggle="dropdown">Category </a>
<div class="dropdown-menu">
<a class="dropdown-item" href="add_cat.php">Add New Category</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="manage_cat.php">Manage Category</a>
</div>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" data-toggle="dropdown">Authors</a>
<div class="dropdown-menu">
<a class="dropdown-item" href="add_author.php">Add New Author</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="manage_author.php">Manage Author</a>
</div>
</li>
<li class="nav-item">
<a class="nav-link" href="issue_book.php">Issue Book</a>
</li>
</ul>
</div>
</nav><br>
<center><h4>Add a new Book</h4><br></center>
<div class="row">
<div class="col-md-4"></div>
<div class="col-md-4">
<form action="" method="post">
<div class="form-group">
<label for="email">Book Name:</label>
<input type="text" name="book_name" class="form-control" required>
</div>
<div class="form-group">
<label for="mobile">Author ID:</label>
<input type="text" name="book_author" class="form-control" required>
</div>
<div class="form-group">
<label for="mobile">Category ID:</label>
<input type="text" name="book_category" class="form-control" required>
</div>
<div class="form-group">
<label for="mobile">Book Number:</label>
<input type="text" name="book_no" class="form-control" required>
</div>
<div class="form-group">
<label for="mobile">Book Price:</label>
<input type="text" name="book_price" class="form-control" required>
</div>
<button type="submit" name="add_book" class="btn btn-primary">Add Book</button>
</form>
</div>
<div class="col-md-4"></div>
</div>
</body>
</html>
<?php
if(isset($_POST['add_book']))
{
$connection = mysqli_connect("localhost","root","");
$db = mysqli_select_db($connection,"lms");
$query = "insert into books values(null,'$_POST[book_name]','$_POST[book_author]','$_POST[book_category]',$_POST[book_no],$_POST[book_price])";
$query_run = mysqli_query($connection,$query);
#header("location:add_book.php");
}
?>
<?php
require("functions.php");
session_start();
#fetch data from database
$connection = mysqli_connect("localhost","root","");
$db = mysqli_select_db($connection,"lms");
$name = "";
$email = "";
$mobile = "";
$query = "select * from admins where email = '$_SESSION[email]'";
$query_run = mysqli_query($connection,$query);
while ($row = mysqli_fetch_assoc($query_run)){
$name = $row['name'];
$email = $row['email'];
$mobile = $row['mobile'];
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Manage Book</title>
<meta charset="utf-8" name="viewport" content="width=device-width,intial-scale=1">
<link rel="stylesheet" type="text/css" href="../bootstrap-4.4.1/css/bootstrap.min.css">
<script type="text/javascript" src="../bootstrap-4.4.1/js/juqery_latest.js"></script>
<script type="text/javascript" src="../bootstrap-4.4.1/js/bootstrap.min.js"></script>
<script type="text/javascript">
function alertMsg(){
alert(Book added successfully...);
window.location.href = "admin_dashboard.php";
}
</script>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="admin_dashboard.php">Library Management System (LMS)</a>
</div>
<font style="color: white"><span><strong>Welcome: <?php echo $_SESSION['name'];?></strong></span></font>
<font style="color: white"><span><strong>Email: <?php echo $_SESSION['email'];?></strong></font>
<ul class="nav navbar-nav navbar-right">
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" data-toggle="dropdown">My Profile </a>
<div class="dropdown-menu">
<a class="dropdown-item" href="">View Profile</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#">Edit Profile</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="change_password.php">Change Password</a>
</div>
</li>
<li class="nav-item">
<a class="nav-link" href="../logout.php">Logout</a>
</li>
</ul>
</div>
</nav><br>
<nav class="navbar navbar-expand-lg navbar-light" style="background-color: #e3f2fd">
<div class="container-fluid">
<ul class="nav navbar-nav navbar-center">
<li class="nav-item">
<a class="nav-link" href="admin_dashboard.php">Dashboard</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" data-toggle="dropdown">Books </a>
<div class="dropdown-menu">
<a class="dropdown-item" href="add_book.php">Add New Book</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="manage_book.php">Manage Books</a>
</div>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" data-toggle="dropdown">Category </a>
<div class="dropdown-menu">
<a class="dropdown-item" href="add_cat.php">Add New Category</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="manage_cat.php">Manage Category</a>
</div>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" data-toggle="dropdown">Authors</a>
<div class="dropdown-menu">
<a class="dropdown-item" href="add_author.php">Add New Author</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="manage_author.php">Manage Author</a>
</div>
</li>
<li class="nav-item">
<a class="nav-link" href="issue_book.php">Issue Book</a>
</li>
</ul>
</div>
</nav><br>
<center><h4>Manage Books</h4><br></center>
<div class="row">
<div class="col-md-2"></div>
<div class="col-md-8">
<table class="table table-bordered table-hover">
<thead>
<tr>
<th>Name</th>
<th>Author</th>
<th>Category</th>
<th>ISBN No.</th>
<th>Price</th>
<th>Action</th>
</tr>
</thead>
<?php
$connection = mysqli_connect("localhost","root","");
$db = mysqli_select_db($connection,"lms");
$query = "select * from books";
$query_run = mysqli_query($connection,$query);
while ($row = mysqli_fetch_assoc($query_run)){
?>
<tr>
<td><?php echo $row['book_name'];?></td>
<td><?php echo $row['author_id'];?></td>
<td><?php echo $row['cat_id'];?></td>
<td><?php echo $row['book_no'];?></td>
<td><?php echo $row['book_price'];?></td>
<td><button class="btn" name=""><a href="edit_book.php?bn=<?php echo $row['book_no'];?>">Edit</a></button>
<button class="btn"><a href="delete_book.php?bn=<?php echo $row['book_no'];?>">Delete</a></button></td>
</tr>
<?php
}
?>
</table>
</div>
<div class="col-md-2"></div>
</div>
</body>
</html>
<?php
session_start();
#fetch data from database
$connection = mysqli_connect("localhost","root","");
$db = mysqli_select_db($connection,"lms");
$book_name = "";
$book_no = "";
$author_id = "";
$cat_id = "";
$book_price = "";
$query = "select * from books where book_no = $_GET[bn]";
$query_run = mysqli_query($connection,$query);
while ($row = mysqli_fetch_assoc($query_run)){
$book_name = $row['book_name'];
$book_no = $row['book_no'];
$author_id = $row['author_id'];
$cat_id = $row['cat_id'];
$book_price = $row['book_price'];
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Dashboard</title>
<meta charset="utf-8" name="viewport" content="width=device-width,intial-scale=1">
<link rel="stylesheet" type="text/css" href="../bootstrap-4.4.1/css/bootstrap.min.css">
<script type="text/javascript" src="../bootstrap-4.4.1/js/juqery_latest.js"></script>
<script type="text/javascript" src="../bootstrap-4.4.1/js/bootstrap.min.js"></script>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="admin_dashboard.php">Library Management System (LMS)</a>
</div>
<font style="color: white"><span><strong>Welcome: <?php echo $_SESSION['name'];?></strong></span></font>
<font style="color: white"><span><strong>Email: <?php echo $_SESSION['email'];?></strong></font>
<ul class="nav navbar-nav navbar-right">
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" data-toggle="dropdown">My Profile </a>
<div class="dropdown-menu">
<a class="dropdown-item" href="">View Profile</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#">Edit Profile</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="change_password.php">Change Password</a>
</div>
</li>
<li class="nav-item">
<a class="nav-link" href="../logout.php">Logout</a>
</li>
</ul>
</div>
</nav><br>
<center><h4>Edit Book</h4><br></center>
<div class="row">
<div class="col-md-4"></div>
<div class="col-md-4">
<form action="" method="post">
<div class="form-group">
<label for="mobile">Book Number:</label>
<input type="text" name="book_no" value="<?php echo $book_no;?>" class="form-control" disabled required>
</div>
<div class="form-group">
<label for="email">Book Name:</label>
<input type="text" name="book_name" value="<?php echo $book_name;?>" class="form-control" required>
</div>
<div class="form-group">
<label for="mobile">Author ID:</label>
<input type="text" name="author_id" value="<?php echo $author_id;?>" class="form-control" required>
</div>
<div class="form-group">
<label for="mobile">Category ID:</label>
<input type="text" name="cat_id" value="<?php echo $cat_id;?>" class="form-control" required>
</div>
<div class="form-group">
<label for="mobile">Book Price:</label>
<input type="text" name="book_price" value="<?php echo $book_price;?>" class="form-control" required>
</div>
<button type="submit" name="update" class="btn btn-primary">Update Book</button>
</form>
</div>
<div class="col-md-4"></div>
</div>
</body>
</html>
<?php
if(isset($_POST['update'])){
$connection = mysqli_connect("localhost","root","");
$db = mysqli_select_db($connection,"lms");
$query = "update books set book_name = '$_POST[book_name]',author_id = $_POST[author_id],cat_id = $_POST[cat_id],book_price = $_POST[book_price] where book_no = $_GET[bn]";
$query_run = mysqli_query($connection,$query);
header("location:manage_book.php");
}
?>
<?php
$connection = mysqli_connect("localhost","root","");
$db = mysqli_select_db($connection,"lms");
$book_count = 0;
$query = "select count(*) as book_count from books";
$query_run = mysqli_query($connection,$query);
while ($row = mysqli_fetch_assoc($query_run)){
$book_count = $row['book_count'];
}
?>
<?php
session_start();
#fetch data from database
$connection = mysqli_connect("localhost","root","");
$db = mysqli_select_db($connection,"lms");
$book_name = "";
$author = "";
$category = "";
$book_no = "";
$price = "";
$query = "select books.book_name,books.book_no,book_price,authors.author_name from books left join authors on books.author_id = authors.author_id";
?>
<!DOCTYPE html>
<html>
<head>
<title>All Reg Books</title>
<meta charset="utf-8" name="viewport" content="width=device-width,intial-scale=1">
<link rel="stylesheet" type="text/css" href="../bootstrap-4.4.1/css/bootstrap.min.css">
<script type="text/javascript" src="../bootstrap-4.4.1/js/juqery_latest.js"></script>
<script type="text/javascript" src="../bootstrap-4.4.1/js/bootstrap.min.js"></script>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="admin_dashboard.php">Library Management System (LMS)</a>
</div>
<font style="color: white"><span><strong>Welcome: <?php echo $_SESSION['name'];?></strong></span></font>
<font style="color: white"><span><strong>Email: <?php echo $_SESSION['email'];?></strong></font>
<ul class="nav navbar-nav navbar-right">
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" data-toggle="dropdown">My Profile </a>
<div class="dropdown-menu">
<a class="dropdown-item" href="#">View Profile</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#">Edit Profile</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="change_password.php">Change Password</a>
</div>
</li>
<li class="nav-item">
<a class="nav-link" href="../logout.php">Logout</a>
</li>
</ul>
</div>
</nav><br>
<center><h4>Registered Book's Detail</h4><br></center>
<div class="row">
<div class="col-md-2"></div>
<div class="col-md-8">
<form>
<table class="table-bordered" width="900px" style="text-align: center">
<tr>
<th>Name</th>
<th>Author</th>
<th>Price</th>
<th>Number</th>
</tr>
<?php
$query_run = mysqli_query($connection,$query);
while ($row = mysqli_fetch_assoc($query_run)){
?>
<tr>
<td><?php echo $row['book_name'];?></td>
<td><?php echo $row['author_name'];?></td>
<td><?php echo $row['book_price'];?></td>
<td><?php echo $row['book_no'];?></td>
</tr>
<?php
}
?>
</table>
</form>
</div>
<div class="col-md-2"></div>
</div>
</body>
</html>
<?php
$connection = mysqli_connect("localhost","root","");
$db = mysqli_select_db($connection,"lms");
$query = "delete from books where book_no = $_GET[bn]";
$query_run = mysqli_query($connection,$query);
?>
<script type="text/javascript">
alert("Book Deleted successfully...");
window.location.href = "manage_book.php";
</script>
Library Management System Project | Software Development
Library Management System is one of the most common software development projects till date. In this article, we are going to make the Library Management System software development project, from scratch, for final year students. We will be covering all the steps you have to do while developing this project.