The CS619 Blood Bank Donation System is one of the most popular final year projects at Virtual University, and this guide builds it completely — in PHP and MySQL — so you can both learn and submit it. You start with the SRS: who uses the system, what it must do, and the rules (56 days between donations, at least 50 kg to donate, a request is fulfilled only when the stock allows it). Then you design the database with an ERD, write the code module by module with line-by-line explanations, test it with 20 test cases, and finish with viva questions and answers. The complete working code is included: login, dashboard, donor management, blood stock, requests and donations. Follow the guide in order and you will have a working project and the understanding to defend it in the viva.
Blood Bank / Blood Donation System — Learn + Build Guide
Course: CS619 Final Project, Virtual University of Pakistan Project: Blood Bank / Blood Donation System (Top Project #7 — 4 projects in 3 semesters: Blood Donation Services and LifeSaver Blood Bank in Fall 2016; Online Blood Bank Management in Spring 2025; Blood on Click in Fall 2025) Stack: PHP + MySQL (XAMPP), as stated in the official specifications (Fall 2016 "Blood Donation Services": HTML, PHP, CSS, JavaScript, Dreamweaver, MySQL; Spring 2025 "Online Blood Bank Management": Microsoft Visual Studio, SQL Server, ASP.NET — this build follows the PHP + MySQL variant) How to use this guide: build the project in the order of this guide — SRS, then Design, then Coding, then Testing, then Viva preparation. Every section first explains the idea in plain English, then shows the work. The complete code is in the files beside this guide; the Coding section explains each module and shows the important code with line-by-line notes.
1. Project overview — what you are building
In an emergency, a patient needs blood of a specific group, and the family has to phone around hospitals and friends to find a donor. That is slow, and slow can be fatal. This system connects the three people involved — the seeker who needs blood, the donor who gives it, and the blood bank staff who keep the stock — in one web application.
What the system does
- The blood bank staff (admin) register donors, record donations, manage the blood stock for all 8 groups, and fulfil blood requests.
- A donor logs in, sees their own donation history and the date they are next allowed to donate.
- A seeker logs in, creates a blood request (patient, group, units, hospital, urgency), searches for donors by blood group and city, and watches their request go from "pending" to "fulfilled".
- The system itself enforces the safety rules: 56 days between donations, at least 50 kg to donate, and a request is fulfilled only when the stock has enough units.
Who uses it
| User | What they can do |
|---|---|
| Admin (blood bank staff) | Everything: donors, stock, requests, donations, dashboard |
| Donor | Search donors, view own donations and next eligible date |
| Seeker | Create requests, view own requests, search donors |
Scope — what is in, and what is not
In scope: login with three roles, donor registration and management, blood stock per group, blood requests with urgency, request fulfilment with a stock check, donation recording with eligibility checks, donor search by blood group and city, dashboard with stock by group.
Out of scope (the official LifeSaver specification mentions SMS alerts to donors in an emergency, but they are not built here): SMS alerts, a mobile app, blood camp management, and printable donation certificates. These are listed as future improvements at the end of this guide. Saying clearly what you did NOT build — and why — is something viva examiners respect.
2. What you will learn (read this before you start coding)
You do not need to know everything below in advance. Learn each item when you reach the module that uses it.
| Topic | Where you use it |
|---|---|
| HTML forms (GET vs POST) | Every page: login, register donor, request, donation |
| PHP basics: variables, if/else, loops, functions | Every file |
PHP sessions ($_SESSION) |
Login: remembering who is logged in |
| MySQL: tables, primary keys, foreign keys | schema.sql |
PDO prepared statements (? placeholders) |
Every database query — this is how SQL injection is stopped |
password_hash() / password_verify() |
Login and donor registration |
SQL transactions (beginTransaction / commit / rollBack) |
Fulfil a request, record a donation — several changes that must happen together |
| SQL joins (donors + users + requests + stock) | Dashboard, donor search, request list |
DATE functions (CURDATE(), DATEDIFF()) |
The 56-day gap between donations, next eligible date |
Suggested order of work (about 4–6 weeks for one student)
- Week 1: install XAMPP, create the database, write the SRS (Section 3).
- Week 2: design the database and draw the ERD (Section 4).
- Weeks 3–4: write the code module by module (Section 5).
- Week 5: run the test cases (Section 6) and fix the bugs they find.
- Week 6: prepare the final report and practise the viva questions (Section 7).
3. SRS — Software Requirements Specification
This section is written so you can copy it into your SRS document (with your own project details) — it follows the sections VU expects in an SRS: purpose, scope, actors, functional requirements, non-functional requirements, and use cases.
3.1 Purpose
To build a web-based Blood Bank Donation System that connects blood seekers with donors and blood banks, so that in an emergency people can find blood of the needed group from a nearby location quickly, and the blood bank can keep an accurate, up-to-date record of its stock.
3.2 Scope
The system covers the daily work of a small blood bank: donor registration, donation recording, stock management for the 8 blood groups, blood requests with urgency, request fulfilment, and donor search by blood group and city. It does not cover SMS alerts, a mobile app, blood camp management, or payment of any kind.
3.3 Actors
- Admin (blood bank staff): manages the whole system — donors, stock, requests and donations. There is one admin account to start with.
- Donor: a registered blood donor. Donors search for other donors and view their own donation history and next eligible date. Donors cannot change the stock or fulfil requests.
- Seeker: someone who needs blood for a patient. Seekers create blood requests and search for donors. Seekers cannot see other seekers' requests.
3.4 Functional requirements
| ID | Requirement |
|---|---|
| FR1 | The system shall let a user log in with a username and password. Wrong credentials shall be rejected with one general error message. |
| FR2 | The system shall show different menus for admin, donor and seeker after login. |
| FR3 | The admin shall register a donor with name, username, email, password, phone, city, blood group and weight. The blood group shall be one of the 8 real groups. |
| FR4 | The admin shall edit a donor (phone, city, weight, available/unavailable status). The blood group shall not be editable, because a person's blood group never changes. |
| FR5 | The admin shall delete a donor only when the donor has no donation history. A donor with donations shall not be deletable. |
| FR6 | Any logged-in user shall search donors by blood group and city. Only donors marked "available" with an active account shall be listed. |
| FR7 | The admin dashboard shall show the stock of all 8 blood groups, total units, total donors, pending requests and recent donations. Groups with 3 or fewer units shall be marked "low stock". |
| FR8 | The admin shall add units to a blood group's stock manually (blood received from a camp or another blood bank). Units added shall be a positive number. |
| FR9 | A seeker shall create a blood request with patient name, blood group, units needed, hospital, city, urgency (normal / urgent / critical) and needed-by date. The needed-by date shall not be in the past. |
| FR10 | The admin shall fulfil a pending request only when the stock of the requested group holds at least the units needed. Fulfilling shall reduce the stock by the units needed and mark the request fulfilled, in one transaction. |
| FR11 | The admin shall record a donation for an available donor. The system shall refuse when: the donor weighs under 50 kg; fewer than 56 days have passed since the donor's last donation; the donation date is in the future. |
| FR12 | On recording a donation, the system shall add the units to the stock of the donor's blood group and set the donor's last donation date, in the same transaction as the donation row. |
| FR13 | A donor shall see only their own donations: date, blood group, units and notes, plus their next eligible date (last donation + 56 days). |
| FR14 | A seeker shall see only their own requests, and may cancel their own pending request. The admin may cancel any pending request. |
3.5 Non-functional requirements
| ID | Requirement |
|---|---|
| NFR1 | Security: passwords shall be stored as hashes, never as plain text. All database queries shall use prepared statements. Pages shall check login on every request. |
| NFR2 | Usability: every action shall show a success or error message. Forms shall keep the typed values when validation fails. |
| NFR3 | Correctness: blood stock shall never go below 0 (enforced by the database CHECK and by the code). A donor's blood group shall never change after registration. |
| NFR4 | Performance: the donor search and the dashboard shall answer in under 2 seconds with the sample data. |
| NFR5 | Portability: the system shall run on XAMPP (Apache + MySQL) on Windows without extra software. |
3.6 Use cases
+-----------------------------+
| Blood Bank Donation System |
| |
Admin ---------->| Login |
| | Manage Donors |
| | Manage Blood Stock |
| | Record Donation |
| | Fulfil Request |
| | View Dashboard |
| |
Donor ---------->| Login |
| | Search Donors |
| | View My Donations |
| |
Seeker --------->| Login |
| Create Blood Request |
| Search Donors |
| View My Requests |
+-----------------------------+
| Use case | Actor | Main flow |
|---|---|---|
| Login | Admin, Donor, Seeker | Enter username + password → system checks credentials → opens the dashboard |
| Register Donor | Admin | Fill the donor form → system validates (group, weight, unique username) → donor created with a login |
| Search Donors | Admin, Donor, Seeker | Pick a blood group and city → system lists available donors |
| Create Blood Request | Seeker | Fill the request form → system validates → request is "pending" |
| Fulfil Request | Admin | Open a pending request → system checks the stock → stock reduced, request fulfilled |
| Record Donation | Admin | Pick a donor → system runs the eligibility checks → donation saved, stock increased |
| View Dashboard | Admin | System shows stock by group, counts, pending requests, recent donations |
| View My Donations | Donor | System shows the donor's own donations and next eligible date |
4. Design
4.1 Architecture
Seeker / Donor / Admin browser
|
| HTTP (forms, links)
v
Apache web server (XAMPP)
|
| PHP files (this project)
v
MySQL database (bloodbank_db)
There is no framework and no JavaScript framework. That is a deliberate choice for a final-year project: every line of code is yours, you can explain all of it in the viva, and nothing is hidden inside a library.
Request flow for every page: config.php (session + database connection)
→ header.php (login check + menu) → page logic → footer.php.
4.2 ERD — Entity Relationship Diagram
users (1) ───< donors (1) >───< donations (N)
users (1) ───< blood_requests (N)
users (1) ───< donations (N) (recorded_by is also a user)
users (1) ───< blood_requests (N) (fulfilled_by is also a user)
blood_stock — one row per blood group (no foreign key; the group is the key)
+----------------+ +----------------+
| users | | donors |
| id (PK) | | id (PK) |
| name | | user_id FK (1) |
| username | | blood_group |
| email | | weight_kg |
| password_hash | | last_donation_ |
| role | | date |
| phone, city | | status |
| status | +-------+--------+
+-------+--------+ |
| 1 | 1
| |
* *
+---v------------+ +----v---------+
| blood_requests | | donations |
| id (PK) | | id (PK) |
| seeker_id (FK) | | donor_id (FK)|
| patient_name | | blood_group |
| blood_group | | units |
| units_needed | | donation_date|
| hospital, city | | notes |
| urgency | | recorded_by |
| needed_by | | (FK) |
| status | +--------------+
| fulfilled_by |
| (FK) |
+-------+--------+
|
+------------------+
| blood_stock |
| id (PK) |
| blood_group |
| (unique) |
| units |
+------------------+
Relationships (read "1" as "one", "N" as "many"):
| Relationship | Meaning |
|---|---|
users 1 — 1 donors (user_id) |
One login account is at most one donor profile; each donor profile belongs to one user. user_id is UNIQUE, and ON DELETE CASCADE removes the profile when the account is deleted. |
donors 1 — N donations (donor_id) |
One donor can donate many times; each donation belongs to one donor. |
users 1 — N blood_requests (seeker_id) |
One seeker can make many requests; each request belongs to one seeker. |
users 1 — N blood_requests (fulfilled_by) |
One admin can fulfil many requests; each request records which admin fulfilled it. |
users 1 — N donations (recorded_by) |
One admin can record many donations; each donation records who recorded it. |
| blood_stock 1 row per group | No foreign key: the blood group itself is the key. There is exactly one stock row per group, enforced by UNIQUE. |
4.3 Database design, table by table
users — everyone who can log in. role is admin, donor or
seeker. password_hash holds a bcrypt hash, never the password itself.
status is active or suspended; a suspended user cannot log in.
city is stored here because donor search needs the donor's city, and
the seeker's city is needed on requests.
donors — the donor profile. user_id is UNIQUE, so one account is
one donor. blood_group is an ENUM of the 8 real groups — the database
itself refuses a made-up group. weight_kg is used for the 50 kg
eligibility rule. last_donation_date is NULL until the first donation;
it drives the 56-day gap check. status is available or
unavailable: a donor who is temporarily unwell is marked unavailable
instead of being deleted, so their history is kept.
blood_stock — one row per blood group, holding the units available
now. Two rules protect these numbers: a database CHECK (units >= 0)
and the code, which only changes them inside a transaction (Sections
5.5 and 5.6). The group column is UNIQUE, so a second row for the same
group can never be created by mistake.
blood_requests — one row per request. units_needed must be above
0 (CHECK). urgency is normal, urgent or critical, and the lists
always sort critical first. status is pending, fulfilled or
cancelled; fulfilled_by is NULL until an admin fulfils it.
donations — one row per donation. blood_group is copied from the
donor profile at the time of the donation, so the record stays correct
even if the profile is edited later. recorded_by is the admin who
recorded it.
Why "next eligible date" is NOT stored. A tempting design is a
column next_eligible_date on the donor. The problem: it is just
last_donation_date + 56 days, so storing it duplicates data — and if
someone edits last_donation_date, the stored date becomes wrong. This
system computes it whenever it is shown. The answer is always correct,
with no extra column. This is a good example to quote in the viva when
asked about a design decision.
4.4 UI flow (page map)
index.php (Login)
|
+-- admin --> dashboard.php (stock by group, pending requests, recent donations)
| |-- donors.php <--> donor_add / donor_edit / donor_delete
| |-- stock.php (add units)
| |-- requests.php <--> fulfil.php
| +-- donate.php
|
+-- donor --> dashboard.php (own profile, next eligible date)
| |-- search_donors.php
| +-- my_donations.php
|
+-- seeker -> dashboard.php (own requests)
|-- request_add.php
|-- requests.php (own requests only)
+-- search_donors.php
4.5 Design decisions worth defending in the viva
- PDO prepared statements everywhere. User input is never pasted into SQL. This stops SQL injection completely.
- Transactions for fulfilment and donation. Fulfilling a request is two changes (request fulfilled + stock reduced); recording a donation is three (donation row + stock increased + last donation date). A transaction makes them atomic: all happen or none does.
FOR UPDATErow lock on fulfilment and donation. If two admins fulfil two requests for the last units at the same moment, the lock makes them wait in turn; the second one then sees the reduced stock and is refused.- Computed next-eligible date (see 4.3) — no stale data, no extra column.
- Blood group as an ENUM, not free text. The database refuses "O++" or "o positive" — only the 8 real groups can ever be stored.
- No framework. Every line is the student's own code and can be explained in the viva.
5. Coding — module by module
Each module is explained in plain English first, then the important code is shown with line-by-line notes. The full code is in the files beside this guide — read the module, then open its file and follow along.
5.1 Module 1 — Configuration and database connection (config.php)
What it does: every page needs two things — a session (to remember
who is logged in) and a database connection. config.php provides both,
plus small helper functions, so no page repeats that setup.
session_start(); // (1)
define('DB_HOST', 'localhost'); // (2)
define('DB_NAME', 'bloodbank_db');
define('DB_USER', 'root');
define('DB_PASS', ''); // XAMPP default: root has no password
define('MIN_DONATION_GAP_DAYS', 56); // (3)
define('MIN_DONOR_WEIGHT_KG', 50);
define('UNITS_PER_DONATION', 1);
const BLOOD_GROUPS = ['A+', 'A-', 'B+', 'B-', // (4)
'AB+', 'AB-', 'O+', 'O-'];
$pdo = new PDO( // (5)
'mysql:host=' . DB_HOST . ';dbname=' . DB_NAME . ';charset=utf8mb4',
DB_USER, DB_PASS,
[PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC]
);
Line by line: (1) session_start() must run before any HTML is printed,
or PHP shows a "headers already sent" error. (2) The database settings
are constants, so they are written once and used everywhere. (3) The
blood bank rules (56 days, 50 kg, 1 unit) are also constants — changing
a rule means changing one line, not searching every file. (4) The 8
blood groups are one constant list, used by every dropdown and every
validation check. (5) PDO is PHP's database layer.
ERRMODE_EXCEPTION means a database error throws an exception instead
of failing silently. FETCH_ASSOC means rows come back as
['blood_group' => 'O+', 'units' => 15] arrays.
Helpers in the same file: e() escapes text before printing it
(stops cross-site scripting); redirect() sends the browser elsewhere;
flash() / showFlash() carry a one-time message to the next page;
isLoggedIn(), isAdmin(), isDonor(), isSeeker() check the role;
requireLogin() and requireAdmin() guard pages; isValidBloodGroup()
checks a group against the constant list before it is used in a query.
5.2 Module 2 — Login and sessions (index.php, logout.php)
What it does: checks a username and password, then remembers the user in the session until logout.
$stmt = $pdo->prepare('SELECT * FROM users WHERE username = ?');
$stmt->execute([$username]);
$user = $stmt->fetch();
if ($user && $user['status'] === 'active'
&& password_verify($password, $user['password_hash'])) {
session_regenerate_id(true);
$_SESSION['user_id'] = (int) $user['id'];
$_SESSION['role'] = $user['role'];
// ... then redirect to the dashboard
}
Line by line: the ? in the query is a placeholder — the username is
sent separately, so even a username like ' OR '1'='1 cannot change the
SQL (this is the SQL-injection defence). password_verify() compares
the typed password with the stored hash; the real password is never in
the database. session_regenerate_id(true) gives the user a fresh
session id after login, so an old session id cannot be reused.
$_SESSION is a server-side array that survives from page to page —
that is how the system "remembers" the login. The error message is
always the same ("Invalid username or password") whether the username
or the password was wrong, so an attacker cannot learn which usernames
exist.
5.3 Module 3 — Donors (donors.php, donor_add.php, donor_edit.php, donor_delete.php)
What it does: list and search donors; register, edit and delete them (admin only).
Search (from donors.php): the WHERE clause is built only from checked
values — the blood group must pass isValidBloodGroup(), and the search
text is bound with ? placeholders, never pasted into the SQL. The list
also shows "donations" per donor, with a subquery that counts that
donor's donations, and the next eligible date, computed from the last
donation date + 56 days.
Registration (from donor_add.php) — two rows in one transaction:
$pdo->beginTransaction();
$stmt = $pdo->prepare(
'INSERT INTO users (name, username, email, password_hash, role, phone, city)
VALUES (?, ?, ?, ?, \'donor\', ?, ?)'
);
$stmt->execute([$name, $username, $email,
password_hash($password, PASSWORD_DEFAULT), $phone, $city]);
$userId = (int) $pdo->lastInsertId();
$stmt = $pdo->prepare(
'INSERT INTO donors (user_id, blood_group, weight_kg) VALUES (?, ?, ?)'
);
$stmt->execute([$userId, $bloodGroup, $weight > 0 ? $weight : null]);
$pdo->commit();
lastInsertId() gives the id of the users row just created, so the
donors row can point at it. If the second insert fails (for example a
duplicate username), the catch block rolls the transaction back and
no half-created donor is left behind. The password is stored with
password_hash($password, PASSWORD_DEFAULT) — a bcrypt hash.
Edit (from donor_edit.php): the blood group is NOT editable, because
a person's blood group never changes. Weight, phone, city and the
available/unavailable status can be changed.
Delete (from donor_delete.php): two rules. First, deletion needs a
confirmation page with a POST form, so a plain link can never delete
anything. Second, a donor with any donation history cannot be deleted,
because the donations table references them — and history is the record
of what happened, so it must not be deleted either.
5.4 Module 4 — Blood stock (stock.php, dashboard stock section)
What it does: shows the units available for all 8 blood groups, and lets the admin add units manually.
The dashboard stock query orders the groups in the usual order (A+, A-,
B+, B-, AB+, AB-, O+, O-) with ORDER BY FIELD(blood_group, 'A+', 'A-',
'B+', 'B-', 'AB+', 'AB-', 'O+', 'O-') — a plain ORDER BY blood_group
would sort them alphabetically (A+, A-, AB+, AB-, B+, ...), which is not
how anyone reads blood groups. Groups with 3 or fewer units get the
low style, so the admin sees the shortage at a glance.
Adding units (from stock.php):
$stmt = $pdo->prepare('UPDATE blood_stock SET units = units + ? WHERE blood_group = ?');
$stmt->execute([$units, $bloodGroup]);
One UPDATE, no transaction needed — it is a single change. The number
must be positive, and the group must pass isValidBloodGroup().
Donations add units automatically (Section 5.6) and fulfilment removes
them (Section 5.5); this form is only for blood received from a camp or
another blood bank.
5.5 Module 5 — Fulfil a blood request (fulfil.php) — the most important module
What it does: gives blood to a patient, after two checks, inside a transaction.
$pdo->beginTransaction(); // (1)
// 1. Re-read the request inside the transaction and lock it.
$stmt = $pdo->prepare("SELECT * FROM blood_requests WHERE id = ? FOR UPDATE");
$stmt->execute([$requestId]);
$req = $stmt->fetch();
if ($req['status'] !== 'pending') {
throw new Exception('This request is already ' . $req['status'] . ' ...');
}
// 2. Stock check — FOR UPDATE locks the stock row.
$stmt = $pdo->prepare('SELECT * FROM blood_stock WHERE blood_group = ? FOR UPDATE');
$stmt->execute([$req['blood_group']]);
$stockRow = $stmt->fetch();
if ((int) $stockRow['units'] < (int) $req['units_needed']) {
throw new Exception('Not enough ' . $req['blood_group'] . ' blood in stock. ...');
}
// All checks passed — fulfil the request and take the units.
$stmt = $pdo->prepare(
"UPDATE blood_requests SET status = 'fulfilled', fulfilled_by = ? WHERE id = ?"
);
$stmt->execute([(int) $_SESSION['user_id'], $requestId]);
$stmt = $pdo->prepare('UPDATE blood_stock SET units = units - ? WHERE blood_group = ?');
$stmt->execute([(int) $req['units_needed'], $req['blood_group']]);
$pdo->commit(); // (2)
Line by line: (1) beginTransaction() starts the transaction — from
here, nothing is saved until commit(). The request is re-read inside
the transaction (not trusted from the earlier page load), because
another admin may have fulfilled it in the meantime. FOR UPDATE locks
both the request row and the stock row: if another admin is fulfilling
a request for the same blood group at the same moment, they wait until
this transaction finishes, then see the updated stock. (2) commit()
saves both changes together. If any check throws an exception, the
catch block calls rollBack() and nothing is saved — the database
can never hold a fulfilled request without stock taken, or stock taken
without a fulfilled request.
Example from the runtime test: a request for 2 units of A+ was fulfilled, and the A+ stock went from 12 to 10 units.
5.6 Module 6 — Record a donation (donate.php)
What it does: records that a donor gave blood, after four checks, inside a transaction.
// 3. 56-day gap check (from donate.php).
if (!empty($donor['last_donation_date'])) {
$daysSince = (int) (new DateTime('today'))
->diff(new DateTime($donor['last_donation_date']))->days;
if ($daysSince < MIN_DONATION_GAP_DAYS) {
$wait = MIN_DONATION_GAP_DAYS - $daysSince;
throw new Exception('This donor last donated ' . $daysSince . ' day(s) ago. '
. 'They must wait ' . $wait . ' more day(s) ...');
}
}
DateTime::diff()->days gives whole days between two dates. The donor
is eligible again exactly 56 days after the last donation. The other
checks: the donor must be "available" with an active account; the donor
must weigh at least 50 kg; the donation date must not be in the future.
The three changes then run in one transaction: insert the donation row,
add the units to the stock (UPDATE blood_stock SET units = units + ?),
and set the donor's last_donation_date. The success message also
tells the admin the next eligible date, computed as the donation date +
56 days.
5.7 Module 7 — Requests, donor search and My Donations (request_add.php, requests.php, search_donors.php, my_donations.php)
What these do: the remaining pages are mostly one form or one list each, and they share two rules worth remembering.
- The seeker id comes from the session, never from the form or the
URL. In
request_add.phpthe insert uses(int) $_SESSION['user_id']as the seeker, so a seeker can never create a request in someone else's name. Inrequests.phpa seeker seesWHERE r.seeker_id = ?with their own id, so they can never see another seeker's requests by changing an address. - The filter is checked against an allowed list. In
requests.phpthefilterparameter is only used after checking it against (all,pending,fulfilled,cancelled), so a made-up filter value can never reach the SQL.
search_donors.php is the emergency page: pick a blood group and a
city, and it lists only donors who are "available" with an active
account — with name, group, city and phone, never login details.
my_donations.php takes the donor id from the session (via the donors
row for that user id), so a donor cannot view another donor's donations.
6. Testing — test cases to run before submission
Run every case below against the working system and record Pass/Fail. A failed case is not a disaster — it is what testing is for; fix the bug, then run the case again.
| ID | Test | Steps | Expected result |
|---|---|---|---|
| TC-1 | Login (admin) | Log in as admin / admin123 | Dashboard opens, admin menu shown, stock by group visible |
| TC-2 | Login (donor) | Log in as donor / donor123 | Dashboard opens, donor profile shown (O+, next eligible date) |
| TC-3 | Login (seeker) | Log in as seeker / seeker123 | Dashboard opens, seeker menu shown (New Request, My Requests) |
| TC-4 | Wrong password | Log in as admin with a wrong password | "Invalid username or password", still on login page |
| TC-5 | Page guard | Open dashboard.php without logging in | Sent back to the login page |
| TC-6 | Role guard | As a seeker, open donors.php directly | Sent back to the dashboard with an error |
| TC-7 | Register donor | Register a new donor, blood group B+, 65 kg | Donor appears in the list with group B+ |
| TC-8 | Duplicate username | Register a donor with username "donor" again | "That username or email is already registered" |
| TC-9 | Underweight donor | Register a donor weighing 45 kg | Refused: must weigh at least 50 kg |
| TC-10 | Search donors | Search blood group O+, city Lahore | Only available O+ donors in Lahore are listed |
| TC-11 | Create request | As seeker, request 2 units of A+ for a patient | Request appears as "pending" |
| TC-12 | Request in the past | Create a request with needed-by date yesterday | Refused: date cannot be in the past |
| TC-13 | Fulfil request | As admin, fulfil the A+ request (2 units) | Request "fulfilled", A+ stock drops by 2 (12 → 10) |
| TC-14 | Fulfil twice | Fulfil the same request again | Refused: request is already fulfilled |
| TC-15 | Fulfil without stock | Request 20 units of AB- (only 2 in stock) and fulfil it | Refused: not enough AB- blood in stock |
| TC-16 | Record donation | Record a donation for a donor who never donated | Donation saved, stock of that group +1, last donation date set |
| TC-17 | Donate too soon | Record a second donation for the same donor the next day | Refused: must wait 56 more days |
| TC-18 | Donate underweight | Record a donation for a donor under 50 kg | Refused: not eligible to donate |
| TC-19 | Delete with history | Delete a donor who has donated | Refused: donor has donation history |
| TC-20 | My Donations privacy | As donor, check My Donations | Only that donor's donations appear, never another donor's |
How to make a donor eligible again for TC-17: the rule is 56 days, so
testing "too soon" is easy (donate, then donate again the next day).
Testing a donation after 56 days is harder — in phpMyAdmin, open the
donors table, find the donor, and set last_donation_date to 60 days
ago. Then record a donation and it should succeed.
7. Viva Q&A — questions the examiner is likely to ask
Q1. What does your project do? It connects blood seekers with donors and blood banks: seekers create blood requests, donors register and donate, and the blood bank staff manage donors, stock and requests. Every donation adds blood to the stock; every fulfilled request takes blood out of it.
Q2. Which technologies did you use, and why? PHP and MySQL on XAMPP — the stack in the official specification for "Blood Donation Services" (HTML, PHP, CSS, JavaScript, MySQL). No framework, so all the code is mine and I can explain every line.
Q3. Show me your database design. Why five tables?
users (login + roles), donors (donor profile), blood_stock (one row
per group), blood_requests (one row per request), donations (one row
per donation). Five tables is enough because a donor is a user with a
profile, a request is a seeker asking for blood, and a donation is a
donor giving blood. The ERD is in Section 4.2.
Q4. What is a foreign key? Give an example from your project.
A column that must match a primary key in another table.
donations.donor_id must be an id from donors — the database
refuses a donation for a donor that does not exist.
Q5. How do you stop SQL injection?
Every query uses PDO prepared statements with ? placeholders. User
input is sent as data, never pasted into the SQL string, so input like
' OR '1'='1 is treated as a plain value, not as SQL.
Q6. How are passwords stored?
With password_hash(), which makes a bcrypt hash. The plain password is
never stored. Login checks with password_verify().
Q7. Why does a donor have to wait 56 days between donations?
Because the body needs about 8 weeks to replace the red blood cells
lost in a donation. Donating sooner would harm the donor. The system
enforces it: last_donation_date + 56 days is the next eligible date.
Q8. How does fulfilling a request change the stock? In one transaction: the request is marked "fulfilled" and the stock of that group is reduced by the units needed. If either change failed, the other would be rolled back, so the data can never be half-updated.
Q9. What is a transaction, and where did you use one? A group of database changes that succeed together or fail together. Fulfilling a request is two changes (request fulfilled + stock reduced) and recording a donation is three (donation row + stock increased + last donation date), so they run in transactions.
Q10. Two admins fulfil two requests for the last units at the same moment. What happens?
The first transaction locks the stock row with FOR UPDATE. The second
waits, then sees the reduced stock and is refused with "not enough blood
in stock". Without the lock, both could succeed and the stock would go
negative.
Q11. How does the system know who is logged in on each page?
PHP sessions. After login, the user id, name and role are stored in
$_SESSION. Every page includes config.php (which starts the session)
and header.php (which calls requireLogin()).
Q12. What is the difference between the three roles? The admin manages donors, stock, requests and donations. The donor searches donors and views their own donations. The seeker creates requests and views their own requests. The menu and the page guards enforce this.
Q13. Why is the blood group an ENUM and not free text? So only the 8 real blood groups can ever be stored. Free text would let someone type "O++" or "o positive", and then the stock and the search would not match. The database itself refuses a wrong group.
Q14. What would you add if you had more time? SMS alerts to nearby donors in an emergency (the LifeSaver specification mentions them), blood camp management, a donor "change my password" page, and a printable donation certificate. SMS would need a new table of alert history and a way to pick donors by city and group — the search page already does the picking.
Q15. What was the hardest bug you fixed? (The student should answer from their own testing — for example the stock going negative when two requests were fulfilled at once, or the 56-day check failing on a donor who had never donated because the last donation date was NULL. Do not memorise an answer to this one; it must be true.)
8. Deliverables checklist (what to submit)
- [ ] SRS document (Section 3 of this guide, written as your own document)
- [ ] Design document (ERD, architecture, UI flow — Section 4)
- [ ] Source code (all files in this folder, working)
- [ ] Database file (
schema.sql) - [ ] Test report (the test cases in Section 6, with Pass/Fail filled in)
- [ ] Final report (what you built, how, and what you learned)
- [ ] Presentation slides for the final viva
- [ ] Demo video or live demo (run the system on your own laptop)
9. Common errors and fixes
| Error / symptom | Cause | Fix |
|---|---|---|
| "Database connection failed" | MySQL is not running, or schema.sql was not imported |
Start MySQL in XAMPP; import schema.sql in phpMyAdmin |
| "Table 'bloodbank_db.users' doesn't exist" | The schema was imported into the wrong database, or not at all | Re-import schema.sql (it creates the database itself) |
| "headers already sent" | Something printed output before session_start() or header() |
Check for blank lines or spaces before <?php in the file; config.php must be included first |
| Login always fails | The sample users were not imported, or the hash was changed | Re-import schema.sql; check the user exists in phpMyAdmin |
| "Not enough B+ blood in stock" | The stock really is short | Record a donation first, or add units on the Blood Stock page — this is correct behaviour, not a bug |
| "must wait ... more day(s)" | The donor donated less than 56 days ago | This is correct behaviour — the 56-day rule protects donors; test with a donor whose last donation was long ago |
| Stock goes below 0 | Changing stock by hand in phpMyAdmin, or code that updates stock without the check | Use fulfil.php and donate.php as written; never update stock by hand |
| Apache will not start | Port 80 is already in use | Stop the other program, or change Apache's port in the XAMPP control panel |
| Page shows nothing (white screen) | A PHP error is hidden by the server settings | Temporarily add error_reporting(E_ALL); ini_set('display_errors', '1'); at the top of config.php to see the message, then remove it |
10. Future improvements
- SMS alerts to donors — when a critical request is created, send an SMS to available donors of that blood group in that city (the LifeSaver specification mentions SMS alerts). Needs an alert-history table and an SMS service.
- Blood camp management — record camps (date, place, organiser) and
the donations made at each camp; the camp's donations add to the stock
the same way
donate.phpdoes. - Change password page — let donors and seekers change their own password after first login instead of the admin setting it.
- Donation certificate — a printable certificate page after a donation, with the donor's name, blood group and date.
- Location-based donor search — the "Blood on Click" specification is about finding blood near the seeker. Add the seeker's area to the search, or sort donors by city distance.
Frequently Asked Questions
- Which stack does this Blood Bank Donation System use? PHP and MySQL on XAMPP, as stated in the official VU specification for "Blood Donation Services" (HTML, PHP, CSS, JavaScript, MySQL). The demo accounts are admin/admin123, donor/donor123 and seeker/seeker123.
- Does the code really work? Yes. It was runtime-verified: all 17 PHP files pass
php -l, the schema imports cleanly into MariaDB, the admin, donor and seeker logins work, a seeker can create a blood request, and fulfilling a request reduces the matching blood-group stock (A+ went from 12 to 10 units in the test). - Can I use this project for my CS619 final year project? Yes — it follows VU's own phases (SRS, design, coding, testing, viva). Change the sample data, add your own features from the future-improvements list, and write the SRS in your own words before submitting.
Comments
Post a Comment