Blood Bank Management System Project
Blood Bank Management System Project
➢ This whole code bundles up the logic for the making of the Blood Bank
Management System Project In PHP.
➢ After downloading the zip file, extract it and place it in the htdocs folder
of your c/xampp folder.
Features
• Login/Logout
• See All Blood Donors
• List Yourself as a Donor
• View Blood types, addresses, and mobile numbers of donors
• Sort donors according to blood type
Setting up project
If you don’t have xampp installed, follow this link.
Before Jumping right into code make sure that you have Xampp installed and
these 2 essential processes running:
1. Apache
2. MySQL
Project Folder
We will do all the code in the C:\xampp\htdocs folder. We will create a new
folder with the name blood-donation and open it in VS code. Before we go
into more detail, we will create the database and the table for the donors.
MySQL database setup
So first, we will create the database and the table for the donors. To make the
required tables we will add a new table by the name ‘bld_dntn’ in the
PHPMyAdmin and then import the SQL file. To import the SQL file, first,
visit http://localhost/phpmyadmin/ in your browser. Now follow the steps below:
2. After that, fill in the text box with ‘bld_dntn’ and hit create button
3. After that go to the import button and select the file and click the
import button on the bottom
donors.sql
--
-- Database: `bld_dntn`
--
-- --------------------------------------------------------
--
-- Table structure for table `donors`
--
--
-- Dumping data for table `donors`
--
--
-- Indexes for dumped tables
--
--
-- Indexes for table `donors`
--
ALTER TABLE `donors`
ADD PRIMARY KEY (`id`);
--
-- AUTO_INCREMENT for dumped tables
--
--
-- AUTO_INCREMENT for table `donors`
--
ALTER TABLE `donors`
MODIFY `id` int(10) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=63;
COMMIT;
db_connection.php
<?php
?>
registe.php
To let a user register himself as a donor, we will create a file
name register.php where we will add both the logic as well as the front-end
code for registering for a donor, and the code for the same will look like this.
The register.php file will let the user register themselves as donors.
<?php
if ($query_run) {
// If it did, show an alert message saying that the message was
successfully sent
echo '<script language="javascript">';
echo 'alert("message successfully sent")';
echo '</script>';
?>
<!DOCTYPE html>
<html>
<head>
</head>
<body>
</body>
</html>
find_blood.php
To let the users access the list of donors and filter them according to blood
types we will add another screen with the help of the file find_blood.php, this
file will also need a bit of javascript to manage the dropdown menu state
which we will define as well.
<?php
ob_start();
session_start();
require "db_connection.php";
?>
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<!-- Output a div element with a "nav" ID and a "col-12" class -->
<div id="nav" class="col-12">
<!-- Output an unordered list -->
<ul>
</div>
<div style="margin: 0; padding: 0 3% 0 7%; text-align: center;">
<!-- Output a div element with a "col-11" class and some inline styles
-->
<div class="col-11" style="background-color: rgba(82, 127, 99,0.5);
padding: 0">
<!-- Output a div element with some inline styles -->
<div style="background-color: rgb(5 85 92);overflow: auto;width:
100%; padding: 5px;">
<!-- Output a form element -->
<form>
<!-- Output a select element with some inline JavaScript -
->
<select name="bloodgroup" onchange="showUser(this.value)"
id="sel">
<option value="">Select Blood Group</option>
<option value="A pos">A+</option>
<option value="A neg">A-</option>
<option value="B pos">B+</option>
<option value="B neg">B-</option>
<option value="O pos">O+</option>
<option value="O neg">O-</option>
<option value="AB pos">AB+</option>
<option value="AB neg">AB-</option>
</select>
</form>
</div>
<!-- Output a div element with some inline styles and an "txtHint"
ID -->
<div id="txtHint" style="padding: 5% 0 5% 0; width: 100%;
overflow: auto;"></div>
</div>
</div>
<?php
?>
<script>
// When the page finishes loading
window.onload = function () {
// Get the value of the PHP variable $a
var val = '<?php echo $a; ?>';
// Get the element with the "sel" ID
var sel = document.getElementById('sel');
// Get the options in the element
var opts = sel.options;
// Loop through the options
for (var opt, j = 0; opt = opts[j]; j++) {
// If the option value matches the value of $a
if (opt.value == val) {
// Set the selected index of the element to the current
option
sel.selectedIndex = j;
// Break out of the loop
break;
}
}
// Get the value of the PHP variable $a
var va = '<?php echo $a; ?>';
// Call the showUser function with the value of $a as an argument
showUser(va);
}
</script>
</body>
</html>
script.js
To assist with the work for dropdowns and their ease of use with cross-
platform browsers we will create another file named script.js within the same
folder.
var myIndex = 0;
function ha(elm) {
window.location = "find_blood.php?bloodgroup=" + elm.value;
}
function showUser(str) {
console.log(str);
if (str == "") {
document.getElementById("txtHint").innerHTML = "";
return;
}
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
} else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function () {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("txtHint").innerHTML = this.responseText;
}
};
xmlhttp.open("GET", "getuser.php?q=" + str, true);
xmlhttp.send();
}
getuser.php
To build the users table inside the find_blood.php page we will facilitate the
functionality with the help of this file named getuser.php.
<!DOCTYPE html>
<html>
<head>
<style>
#customers {
font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
border-collapse: collapse;
width: 100%;
}
#customers td,
#customers th {
border: 1px solid green;
padding: 25px;
}
#customers tr:nth-child(even) {
background-color: #f2f2f2;
}
#customers tr:hover {
background-color: green;
}
#customers th {
padding-top: 12px;
padding-bottom: 12px;
text-align: left;
background-color: #504caf;
color: white;
}
</style>
</head>
<body>
<?php
// Select all rows from the "donors" table where the "bloodgroup" column
matches the value of the "q" parameter
$sql = "SELECT * FROM donors WHERE bloodgroup = '" . $q . "'";
?>
</body>
</html>
index.php
By default, if we visit http://localhost/blood-donation/ it will look for
an index.php file that we will define and redirect its contents to be
from find_blood.php.
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="main.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-
awesome/4.7.0/css/font-awesome.min.css">
<script type="text/javascript" src="script.js"></script>
</head>
<body>
<?php include "find_blood.php"; ?>
</body>
</html>
logout.php
To log the user out we will write the logic for the same under
the logout.php file.
<?php
?>
main.css
Though most of the styling is done with bootstrap there are instances where
we needed an extra file for custom CSS. To accommodate the same we will
create a file named main.css within the same folder.
* {
box-sizing: border-box;
}
body {
margin: 0px;
}
#info {
overflow: hidden;
z-index: 10;
position: absolute;
text-align: center;
overflow: auto;
left: 0;
top: 400px;
-webkit-animation: myfirst1 0.5s ease-in-out 0.1s 1 normal;
animation: myfirst1 0.5s ease-in-out 0.1s 1 normal;
}
#info1 {
position: absolute;
left: 35%;
top: 150px;
font-size: 16px;
font-size: 3vw;
color: rgb(252, 5, 5);
text-shadow: 1px 1px 2px black;
z-index: 10;
}
form select {
#comname {
width: 100%;
padding: 0 20% 0 20%;
margin: 0;
position: absolute;
text-align: center;
top: 20px;
font-size: 25px;
color: rgb(255, 255, 255);
text-shadow: 1px 1px 2px black, 0 0 25px blue, 0 0 5px darkblue;
z-index: 10;
}
#comname i.fa {
padding: 0;
margin: 0;
font-size: 50px;
height: 0;
text-align: center;
text-decoration: none;
background: transparent;
color: white;
z-index: 100;
}
#nav {
position: absolute;
left: 0;
z-index: 100;
padding: 0;
background-color: rgba(13, 23, 17, 0.995);
display: flex;
align-self: center;
flex-wrap: nowrap;
justify-content: space-around;
}
#nav ul {
list-style-type: none;
/* margin: 0 20% 0 20%; */
padding: 0;
overflow: hidden;
background-color: transparent;
}
#nav li {
float: left;
}
#nav li a {
display: block;
color: white;
font-weight: bold;
text-align: center;
letter-spacing: 2px;
padding: 14px 16px;
text-decoration: none;
}
#nav li a:hover {
background-color: #504caf;
}
.active {
background-color: #504caf;
}
a.fa {
padding: 10px;
font-size: 15px;
width: 30px;
text-align: center;
text-decoration: none;
margin: 5px 2px;
border-radius: 50%;
background: rgba(82, 127, 99, 0.5);
color: white;
}
a.fa-facebook:hover {
background: #3B5998;
color: white;
}
a.fa-twitter:hover {
background: #55ACEE;
color: white;
}
a.fa-google:hover {
background: #dd4b39;
color: white;
}
a.fa-youtube:hover {
background: #bb0000;
color: white;
}
a.fa-instagram:hover {
background: #125688;
color: white;
}
#upper h5 {
font-size: 20px;
color: white;
}
.qw {
background-color: rgba(82, 127, 99, 0.5);
border-radius: 5px;
height: 40px;
width: 50%;
border-width: 0;
}
.qw a {
text-decoration: none;
color: white;
}
.qw:hover {
background: #bb0000;
}
i.fa {
padding: 35px;
font-size: 50px;
width: 120px;
height: 120px;
text-align: center;
text-decoration: none;
margin: 5px 2px;
border-radius: 50%;
background: rgba(82, 127, 99, 0.5);
color: white;
}
/* For desktop: */
.col-1 {
width: 8.33%;
}
.col-2 {
width: 16.66%;
}
.col-3 {
width: 25%;
}
.col-4 {
width: 33.33%;
}
.col-5 {
width: 41.66%;
}
.col-6 {
width: 50%;
}
.col-7 {
width: 58.33%;
}
.col-8 {
width: 66.66%;
}
.col-9 {
width: 75%;
}
.col-10 {
width: 83.33%;
}
.col-11 {
width: 91.66%;
}
.col-12 {
width: 100%;
}
#nav ul {
margin: 0 0 0 0;
font-size: 2vw;
}
.info2 {
position: absolute;
top: 100px;
font-weight: bolder;
font-size: 16px;
font-size: 4vw;
color: rgb(254, 7, 7);
text-shadow: 1px 1px 2px black;
z-index: 10;
}
div.container {
padding: 10px;
}
.in {
color: rgb(255, 255, 255);
background: rgba(0, 0, 0, 0.5);
font-size: 15px;
font-weight: bold;
padding: 2px 10px;
width: 100%;
height: 50px;
*width: 100%;
*background: rgba(0, 0, 0, 0.5);
box-sizing: border-box;
display: inline-block;
border: 1px solid #ccc;
}
.in:focus {
background: transparent;
*background: transparent;
color: black;
}
.im {
width: 120px;
height: 120px;
border-radius: 10px;
}
.im:hover {
opacity: 0.4;
}
.container {
padding: 16px;
}
OUTPUT