Skip to main content
Flox Blog Beginner's Guide for Web Developers. 60% Off in Website Design & Development click here.

How to create simple blood donation management system in PHP code?

How to create simple blood donation management system in PHP code

In this example we will create a simple blood donation management system in core PHP code.

First you will create a folder in XAMPP Server like “online-blood-donation-system“. This is the folder of your project. Now create all sub folder like js, css, images etc. In my case i don’t use any JavaScript and Image, So i don’t create any folder related¬† to these name. One more thing i use bootstrap in my project so you will download the bootstrap.css file from internet.

Now we will start coding, so go to any text editor what you like and create a file name header.php and type the header html code.

header.php

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Online Blood Donation System</title>
<link href="css/bootstrap.css" rel="stylesheet" type="text/css">
<link href="css/common.css" rel="stylesheet" type="text/css">
</head>

<body>
<header class="header_area_holder container-fluid text-center">
  <div class="row">
    	<div class="col-md-12">
        	<h1>Online Blood Donation System</h1>
        </div>
    </div>
</header>

Now we are create footer.php file.

footer.php

<footer class="footer_area_holder container-fluid text-center">
	<div class="row">
    	<div class="col-md-12">
        	<p><a href="https://www.floxblog.com/" target="_blank">Flox Blog</a> 2019.</p>
        </div>
    </div>
</footer>
</body>
</html>

Then create index.php file.

index.php

<?php include 'header.php';?>
<section class="container_area_holder container-fluid home_area_holder">
  <div class="container">
    	<div class="row">
            <div class="col-md-2"></div>
            <div class="col-md-3 left">
                <a href="doner.php">Blood Doner</a>
            </div>
            <div class="col-md-2"></div>
            <div class="col-md-3 right">
                <a href="receiver.php">Blood Receiver</a>
            </div>
            <div class="col-md-2"></div>
        </div>
    </div>
</section>
<?php include 'footer.php';?>

Now you will see home page structure is ready for action. Then create a database in phpmyadmin. In my case the database name is php_blooddonor.

php_blooddonor.sql

CREATE TABLE `donor` (
  `id` int(11) NOT NULL,
  `name` varchar(225) NOT NULL,
  `phone` varchar(225) NOT NULL,
  `blood_type` varchar(225) NOT NULL,
  `address` varchar(225) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

Then create a database connection file in php. Name it config.php

config.php

<?php
$link=mysqli_connect("localhost","root","","php_blooddonor");
?>

Create a doner.php for insert data to the database or you called as form page.

doner.php

<?php 
session_start();
if(isset($_SESSION['msg'])){
  echo $_SESSION['msg'];
  unset($_SESSION['msg']);
}
include 'header.php';
include_once("config.php");
?>
<?php
if(isset($_POST["submit"]))
{
$name=$_POST["name"];
$phone=$_POST["phone"];
$blood_type=$_POST["blood_type"];
$address=$_POST["address"];
$sql="insert into donor(name,phone,blood_type,address) values('$name','$phone','$blood_type','$address')";
$query=mysqli_query($link,$sql);
 if($query){
    
    echo $msg= "<span style='color:red';>registration sucessfull</span>";
    }
  else
    {
     echo $msg="<span style='color:red'>Invalid UID / Token NO</span>";

       }

      }
 ?>
<section class="container_area_holder doner_area_holder">
  <div class="container">
    <div class="row">
      <div class="col-md-12">
        <div class="form_holder">
          <form action="doner.php" method="post">
            <label>Blood Doner Form</label>
            <input type="text" placeholder="Name" name="name" id="nameid" required>
            <input type="tel" placeholder="Phone Number" name="phone" required>
            <select name="blood_type" required>
              <option>Select Blood Group</option>
              <option value="O+">O+</option>
              <option value="A+">A+</option>
              <option value="B+">B+</option>
              <option value="AB+">AB+</option>
              <option value="O-">O-</option>
              <option value="A-">A-</option>
              <option value="B-">B-</option>
              <option value="AB-">AB-</option>
            </select>
            <textarea placeholder="Address" name="address"></textarea>
            <input type="submit" name="submit" value="Register">
          </form>
        </div>
      </div>
    </div>
  </div>
</section>


<?php include 'footer.php';?>


Then you create a receiver.php for the list of all blood groups.

receiver.php

<?php include 'header.php';
include_once("config.php");
?>
<section class="container_area_holder receiver_area_holder">
  <div class="container">
    	<div class="row">
            <div class="col-md-3 box_1">
                <a href="recievercode.php?blood_group='O+'">O+</a>
            </div>
            <div class="col-md-3 box_2">
                <a href="recievercode.php?blood_group='A+'">A+</a>
            </div>
            <div class="col-md-3 box_3">
                <a href="recievercode.php?blood_group='B+'">B+</a>
            </div>
            <div class="col-md-3 box_4">
                <a href="recievercode.php?blood_group='AB+'">AB+</a>
            </div>
            <div class="col-md-3 box_5">
                <a href="recievercode.php?blood_group='<?php echo 'O-';?>'">O-</a>
            </div>
            <div class="col-md-3 box_6">
                <a href="recievercode.php?blood_group='<?php echo 'A-';?>'">A-</a>
            </div>
            <div class="col-md-3 box_7">
                <a href="recievercode.php?blood_group='<?php echo 'B-';?>'">B-</a>
            </div>
            <div class="col-md-3 box_8">
                <a href="recievercode.php?blood_group='<?php echo 'AB-';?>'">AB-</a>
            </div>
        </div>
    </div>
</section>


<?php include 'footer.php';?>

Create a recievercode.php file for display all name and data of a selected group peoples.

recievercode.php

<?php include 'header.php';
include_once("config.php");
?>
<form method="post">
<table border="2">
<tr>
  <th>ID</th>
    <th>Name</th>
    <th>Phone</th>
    <th>Blood Type</th>
    <th>Address</th>
</tr>
<tr>
<?php
$blood_group=str_replace("%27","",urlencode($_GET['blood_group']));
$sql="select * from donor where blood_type='$blood_group'";
$query=mysqli_query($link,$sql);
while($row=mysqli_fetch_assoc($query)) : ?>
<td><?=$row['id'];?></td>
<td><?=$row['name'];?></td>
<td><?=$row['phone'];?></td>
<td><?=$row['blood_type'];?></td>
<td><?=$row['address'];?></td>
</tr>
<?php endwhile; ?>
</table>


</form>
<?php include 'footer.php';?>

Now it’s time for styling code, so code is here.

@charset "utf-8";
/* CSS Document */
a{transition:.6s;}
a{ text-transform:uppercase; text-decoration:none;}
a:hover{text-decoration:none;}
th,
td{ padding:10px;}
.header_area_holder{ background-color:#4058a5; color:#fff;}
.header_area_holder h1{font-size:25px; margin:0; padding:20px;}

.container_area_holder{ padding-bottom:44px; padding-top:20px;}
.home_area_holder{ text-align:center; padding-top:80px;}
.home_area_holder .col-md-3 a{ padding:90px 20px; display:block; text-transform:uppercase; color:#fff;}
.home_area_holder .col-md-3.left a{ background-color:#7813bf;}
.home_area_holder .col-md-3.right a{ background-color:#3094e1;}
.home_area_holder .col-md-3 a:hover{background-color:#202020;}

.receiver_area_holder .col-md-3{ text-align:center; margin-bottom:30px;}
.receiver_area_holder .col-md-3 a{ padding:50px 20px; display:block; background-color:#202020; color:#fff; font-weight:bold; font-size:23px;}
.receiver_area_holder .col-md-3.box_1 a{background-color:#e66565;}
.receiver_area_holder .col-md-3.box_2 a{background-color:#ce52cf;}
.receiver_area_holder .col-md-3.box_3 a{background-color:#8d52cf;}
.receiver_area_holder .col-md-3.box_4 a{background-color:#5255cf;}
.receiver_area_holder .col-md-3.box_5 a{background-color:#52b3cf;}
.receiver_area_holder .col-md-3.box_6 a{background-color:#8dcf52;}
.receiver_area_holder .col-md-3.box_7 a{background-color:#d3b342;}
.receiver_area_holder .col-md-3.box_8 a{background-color:#d37942;}
.receiver_area_holder .col-md-3 a:hover{background-color:#222222;}

table{margin: 0 auto; margin-top:50px;}

.form_holder{ max-width:500px; margin:0 auto;}
.doner_area_holder label{ text-align:center; font-weight:bold; font-size:25px; display:block;}
.doner_area_holder input,
.doner_area_holder select,
.doner_area_holder textarea{ display:block; width:100%; border:2px solid #CCC; padding:10px 20px; margin-bottom:20px;}
.doner_area_holder input[type="submit"]{ background-color:#4058a5; color:#fff; border-color:#4058a5; cursor:pointer;}
.footer_area_holder{ float:left; width:100%; position:absolute; bottom:0; left:0; background-color:#222222; color:#fff;}
.footer_area_holder p{ margin:0; padding:10px 0;}

create simple blood donation management system in PHP.

Then run the site in your localhost and test this. This is a simple php programmin every one understand what i am saying in this code. If you have any issue or any question then comment below and ask your question, i will deffenity answer your question.

If you area a WordPress developer or designer you will see my other post for more experience and improve your skills in development platform.

If you like my article please share with your friends. Thank You!!!.

Leave a Reply

avatar
  Subscribe  
Notify of
F