This guide walks you through building a Hospital Management System in PHP and MySQL from the ground up, a complete project for managing patients, doctors, appointments, and admissions, with source code. Instead of only downloading it, you will understand how each part works: the database schema, the relationships between patients, doctors, and appointments, the booking logic, and the admin dashboard. That understanding is what turns a downloaded project into something you can explain in a viva, extend for an assignment, or showcase in your portfolio.
Jump to download & setup
- What a hospital management system does
- The database schema (patients, doctors, appointments, departments)
- How patient and doctor management work
- How appointment booking works
- How the relationships tie together with JOINs
- The admin dashboard and login
- Setup: running it on your machine
- How to extend it for your own project
1. What a hospital management system does
A hospital management system is software a hospital uses to run its core operations: registering patients, maintaining doctor and department records, scheduling appointments between patients and doctors, and tracking visits or admissions. It replaces scattered paper records with one reliable, searchable system. Building one in PHP and MySQL is one of the most popular and respected student projects because it is larger and more relational than a typical store project, exercising database design, multiple table relationships, CRUD, authentication, and booking logic in a context everyone understands.
The version in this guide includes patient management, doctor management organized by department, appointment scheduling, a secure login, and an admin dashboard. That is enough to be a complete, demonstrable project while staying clear enough to fully understand.
2. The database schema
The schema is the backbone of the project, and a hospital system has a richer one than most, which is part of why it impresses. Reading the tables tells you what the system models. The hospital system uses these core tables.
| Table | What it stores | Key columns |
|---|---|---|
departments | Hospital departments | id, name |
doctors | Each doctor, in a department | id, name, department_id, specialization, phone |
patients | Each registered patient | id, name, age, gender, phone, address |
appointments | A scheduled visit | id, patient_id, doctor_id, appointment_date, status |
The relationships are the key idea, and there are several, which is what makes this project a strong demonstration of relational design. Each doctor belongs to a department, a patient can have many appointments, a doctor can have many appointments, and the appointments table links a patient to a doctor for a specific date. The foreign keys, department_id on doctors, and patient_id and doctor_id on appointments, are what tie everything together. Understanding this diagram is understanding most of the project.
3. How patient and doctor management work
Both are CRUD: add, view, edit, delete, each operation a small block of PHP running an SQL statement. Adding a patient, with values from a form, uses a prepared statement:
// add a patient (simplified) $stmt = $conn->prepare( "INSERT INTO patients (name, age, gender, phone, address) VALUES (?, ?, ?, ?, ?)" ); $stmt->bind_param("sisss", $name, $age, $gender, $phone, $address); $stmt->execute();
The prepared statement with bind_param, rather than dropping form values into the SQL string, is how you prevent SQL injection, a core security habit in PHP and a detail that marks a project you understand rather than one you copied. Doctors are managed the same way, with each doctor assigned to a department by selecting from the departments list.
4. How appointment booking works
Booking is where the tables come together. The admin or a patient selects a patient, a doctor, and a date, and the system inserts a row into the appointments table linking the two by their IDs with the chosen date and an initial status of pending or confirmed.
// book an appointment (simplified) $stmt = $conn->prepare( "INSERT INTO appointments (patient_id, doctor_id, appointment_date, status) VALUES (?, ?, ?, 'pending')" ); $stmt->bind_param("iis", $patientId, $doctorId, $date); $stmt->execute();
A well-built version can also check that the chosen doctor is not already booked at that time before confirming, which is a small but impressive piece of real-world logic to add. The status column then lets staff move an appointment through pending, confirmed, and completed.
5. How the relationships tie together with JOINs
The payoff of the relational design is readable, useful views built with JOINs. To list appointments with the patient’s name, the doctor’s name, and the doctor’s department, all at once, the query joins three tables:
// appointments with patient, doctor, and department names SELECT a.appointment_date, a.status, p.name AS patient, d.name AS doctor, dep.name AS department FROM appointments a JOIN patients p ON a.patient_id = p.id JOIN doctors d ON a.doctor_id = d.id JOIN departments dep ON d.department_id = dep.id ORDER BY a.appointment_date
This single query, with three joins, turns four normalized tables back into one human-readable schedule. Understanding why each join is needed, one to reach the patient, one to reach the doctor, and one more to reach that doctor’s department, is understanding the heart of relational databases. Being able to walk an examiner through this query demonstrates genuine command of the project.
6. The admin dashboard and login
The system sits behind a login that verifies a hashed password with password_verify and uses a role to separate staff from the admin. The dashboard is a set of small queries you now understand: total patients, total doctors, today’s appointments, and appointments by status. Because you know the schema and how joins work, you can add any new dashboard figure yourself just by writing its query, which is the flexibility that makes the project worth understanding rather than just running.
7. Setup: running it on your machine
To run the project locally you need a PHP environment with MySQL, most commonly XAMPP on Windows or its equivalent on Mac and Linux. The steps are:
- Install XAMPP and start the Apache and MySQL services.
- Copy the project folder into the
htdocsdirectory. - Open phpMyAdmin, create a database, and import the included
.sqlfile to create the tables. - Open the project’s config file and set the database name, user, and password to match your setup.
- Visit the project in your browser through
localhostand log in with the default admin credentials in the guide.
The complete hospital management system in PHP and MySQL, including all source files and the database, is ready to download and run by following the steps above.
Download source code
Replace this link with your actual download URL.
8. How to extend it for your own project
Assignments and portfolios reward what you add, not what you copied. Because you now understand the schema and the relationships, here are natural extensions you can build and explain:
- Patient medical history: a records table linked to patients and appointments for diagnoses and notes.
- Prescriptions and billing: generate prescriptions and bills tied to each appointment.
- Admissions and beds: track inpatient admissions and bed availability by ward.
- Doctor availability: store each doctor’s available slots and prevent double-booking.
- Reports: appointments per department, patients per day, or revenue, using
GROUP BY.
Each is a small, well-scoped addition that demonstrates real understanding, exactly what turns a standard download into a project you can defend and be proud of.
Frequently asked questions
What is a hospital management system in PHP?
It is a web application that manages patients, doctors, departments, and appointments for a hospital, built with PHP and MySQL. It is a popular and respected student project because it is larger and more relational than typical projects, covering database design, multiple table relationships, CRUD, and authentication.
What database tables does it use?
The core schema has departments, doctors (each in a department), patients, and appointments (linking a patient to a doctor). The several foreign-key relationships are what make this project a strong demonstration of relational design.
How does appointment booking work?
The system records an appointment by inserting a row into the appointments table that links a patient and a doctor with a date and status. A stronger version also checks that the doctor is not already booked at that time.
Can I use this as my college or university project?
Yes. It is one of the most respected academic projects, and because this guide explains the schema, the relationships, and the JOIN queries, you can confidently answer questions in a viva. Adding one of the suggested extensions makes it stronger still.
Is the source code free to download?
Yes, the full hospital management system source code is available to download for free using the link in the download section above.
Hospital Management System(Health Care Hospital) is designed for managing details about hospital patient,employee and rooms(10). Designed by using HTML / CSS / JS / JQUERY/ PHP (procedural php) / MYSQL and developed by Jayendra Matarage. Languages and Framworks HTML CSS JS PHP (procedural php) MYSQL JQUERY BOOTSTRAP
Features overview of Hospital Management System:
- Login and make basic account
- Setup user account
- Options for top level admin functions
- Patient info registration
- Patient functions such as Make OPD invoice, Admit to Hospital and more
- Edit/Update/Delete data functions
- Patient Invoices
- Room availability
- Admin Patient Information
Installation Steps:
- Create a new database ‘hospitol’
- Import the database file from the ‘Database’ folder
Important note is given on a file within the project folder. Be sure to read the file before running the application.
If you need help regarding how to open or run php programs, see the video below:
DOWNLOAD Hospital Management System in PHP And MYSQL with source code FOR FREE

