Finally, I am uploading an online doctor's appointment booking system source code. many people requesting source code on my youtube channel "Tech. Rudranshi".



In the system, there is too many options to handle your hospital like adding a new doctor, new department, and patient also can book the appointment and one more thing admin panel is also so good there you can also add the department and add new doctors. same thing penitent also can choose department there doctors.


You can get working source code there is two options:

  1. you can download the complete working source code of the zip file or 
  2. you can copy and paste from my code snippets


File Structure:

doctors-appointment/
┣ admin/
┃ ┣ dashboard/
┃ ┃ ┣ doctors.php
┃ ┃ ┣ footer.php
┃ ┃ ┣ header.php
┃ ┃ ┣ index.php
┃ ┃ ┣ logout.php
┃ ┃ ┗ style.css
┃ ┣ index.php
┃ ┣ process_login.php
┃ ┗ style.css
┣ assets/
┃ ┣ css/
┃ ┃ ┗ style.css
┃ ┗ img/
┃   ┗ img-3.jpg
┣ config.php
┣ doctorappointment.sql
┣ doctors_list.php
┣ index.php
┗ success.php


doctors-appointment/index.php

<?php include_once './config.php'; ?>
<!DOCTYPE html>
<html>
    <head>
        <title></title>
        <!-- Latest compiled and minified CSS -->
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" crossorigin="anonymous">
        <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
        <link href="assets/css/style.css" rel="stylesheet" type="text/css"/>
        <link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/timepicker/1.3.5/jquery.timepicker.min.css">
    </head>
    <body>  
        <div class="container">
            <div class="row align-items-center">
                <div class="col-lg-6 ">
                    <div class="appoinment-content">
                        <img src="assets/img/img-3.jpg" alt="" class="img-fluid"/>
                        <div class="emergency">
                            <h2 class="text-lg"><i class="icofont-phone-circle text-lg"></i>+91 88272 13789</h2>
                        </div>
                    </div>
                </div>
                <div class="col-lg-6 col-md-10 ">
                    <div class="appoinment-wrap mt-5 mt-lg-0">
                        <h2 class="mb-2 title-color">Book appoinment</h2>
                        <p class="mb-4">
                            Now you can get an online appointment, We will get back to you and fix a meeting with doctors.
                        </p>

                        <?php
                        if (isset($_POST['submit'])) {

                            if (isset($_POST['department']) && !empty($_POST['doctors']) && !empty($_POST['date']) && !empty($_POST['time']) && !empty($_POST['name']) && !empty($_POST['phone']) && !empty($_POST['message'])) {
                                $statement = $DB->prepare('INSERT INTO appoinments (doctor,department,app_date,app_time,patient_name,phone,msg) VALUES (:doctor,:department,:app_date,:app_time,:patient_name,:phone,:msg)');



                                $is_done = $statement->execute([
                                    'doctor' => $_POST['doctors'],
                                    'department' => $_POST['department'],
                                    'app_date' => $_POST['date'],
                                    'app_time' => $_POST['time'],
                                    'patient_name' => $_POST['name'],
                                    'phone' => $_POST['phone'],
                                    'msg' => $_POST['message'],
                                ]);

                                if ($is_done) {
                                    echo "<p class='success'>Your appointment has been taken!</p>";
                                    header("Refresh:1;url= success.php");
                                }
                            } else {
                                echo "<p class='error'>Fill out the all form data!</p>";
                            }
                        }
                        ?>

                        <form id="#" class="appoinment-form" method="post" action="#">
                            <div class="row">
                                <div class="col-lg-6">
                                    <div class="form-group">
                                        <select class="form-control" id="department" name="department">
                                            <option>Choose Department</option>
                                            <?php
                                            $stmt = $DB->prepare("SELECT * FROM department");
                                            $stmt->execute();
                                            $departments = $stmt->fetchAll();
                                            ?>
                                            <?php foreach ($departments as $department): ?>
                                                <option value="<?php echo $department['name']; ?>"><?php echo $department['name']; ?></option>
                                            <?php endforeach; ?>
                                        </select>
                                    </div>
                                </div>
                                <div class="col-lg-6">
                                    <div class="form-group">
                                        <select class="form-control" id="doctors" name="doctors"></select>
                                    </div>
                                </div>

                                <div class="col-lg-6">
                                    <div class="form-group">
                                        <input name="date" id="date" type="text" class="form-control" placeholder="dd/mm/yyyy">
                                    </div>
                                </div>

                                <div class="col-lg-6">
                                    <div class="form-group">
                                        <input name="time" id="time" type="text" class="form-control" placeholder="Time">
                                    </div>
                                </div>
                                <div class="col-lg-6">
                                    <div class="form-group">
                                        <input name="name" id="name" type="text" class="form-control" placeholder="Full Name">
                                    </div>
                                </div>

                                <div class="col-lg-6">
                                    <div class="form-group">
                                        <input name="phone" id="phone" type="Number" class="form-control" placeholder="Phone Number">
                                    </div>
                                </div>
                            </div>
                            <div class="form-group-2 mb-4">
                                <textarea name="message" id="message" class="form-control" rows="6" placeholder="Your Message"></textarea>
                            </div>

                            <input type="submit" name="submit" class="btn btn-main btn-round-full" value="Make Appoinment">
                        </form>
                    </div>
                </div>
            </div>
        </div>

        <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
        <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
        <script src="//cdnjs.cloudflare.com/ajax/libs/timepicker/1.3.5/jquery.timepicker.min.js"></script>
        <script>
            $(document).ready(function () {
                $('#department').change(function () {

                    var path = "doctors_list.php";
                    var department = $("#department").val();
                    $.ajax({
                        type: "POST",
                        url: path,
                        data: {
                            department: department
                        },
                        success: function (data) {
                            $('#doctors').html(data);
                        }
                    });

                    return false;


                });

                //jquery datepicker
                $("#date").datepicker({
                    dateFormat: 'dd/mm/yy',
                    minDate: 0
                });


                //timepicker
                $('#time').timepicker({

                });
            });

        </script>

    </body>
</html>


doctors-appointment/config.php

<?php
error_reporting( E_ALL & ~E_DEPRECATED & ~E_NOTICE );
ob_start();
session_start();

define('DB_DRIVER', 'mysql');
define('DB_SERVER', 'localhost');
define('DB_SERVER_USERNAME', 'root');
define('DB_SERVER_PASSWORD', '');
define('DB_DATABASE', 'doctorappointment');


define('PROJECT_NAME', 'Appointment');
$dboptions = array(
              PDO::ATTR_PERSISTENT => FALSE, 
              PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, 
              PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
              PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8',
            );

try {
  $DB = new PDO(DB_DRIVER.':host='.DB_SERVER.';dbname='.DB_DATABASE, DB_SERVER_USERNAME, DB_SERVER_PASSWORD , $dboptions);  
} catch (Exception $ex) {
  echo $ex->getMessage();
  die;
}

//get error/success messages
if ($_SESSION["errorType"] != "" && $_SESSION["errorMsg"] != "" ) {
    $ERROR_TYPE = $_SESSION["errorType"];
    $ERROR_MSG = $_SESSION["errorMsg"];
    $_SESSION["errorType"] = "";
    $_SESSION["errorMsg"] = "";
}
?>


doctors-appointment/doctors_list.php

<?php
include './config.php';
$stmt = $DB->prepare("SELECT * FROM doctors WHERE department = :department");
$stmt->bindParam(":department", $_POST['department']);
$stmt->execute();
$data_doctors = $stmt->fetchAll();
?>
<option>Select Doctors</option>
<?php foreach ($data_doctors as $doctor): ?>
<option value="<?php echo $doctor['name']; ?>"><?php echo $doctor['name']; ?></option>
<?php endforeach; ?>


doctors-appointment/assets/css/style.css

/*
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
*/
/* 
    Created on : Apr 23, 2021, 10:52:55 AM
    Author     : GWeb Solution PC 1
*/

.emergency{
    position: absolute;
    bottom: 27px;
    z-index: 1;
    background: #50c3ef;
    color: #fff;
    text-align: center;
    width: 100%;
}

.appoinment-content{
    position: relative;
}

.appoinment-content img{
    width: 100%;
}

.btn-main{
    background: #50c3ef;
}

.error{
    background: yellow;
    color: red;
    padding: 5px;
}

.success{
    background: #50c3ef;
    color: #fff;
    padding: 5px;
}


/*jquery  ui datepicker*/


doctors-appointment/admin/index.php

<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Untitled</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.min.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/ionicons/2.0.1/css/ionicons.min.css">
    <link rel="stylesheet" href="style.css">
</head>

<body>
    <div class="login-dark">
        <form method="post" action="process_login.php">
            <h2 class="sr-only">Login Form</h2>
            <div class="illustration"><i class="icon ion-ios-locked-outline"></i></div>
            <div class="form-group"><input class="form-control" type="text" name="username" placeholder="Username"></div>
            <div class="form-group"><input class="form-control" type="password" name="password" placeholder="Password"></div>
            <div class="form-group"><button class="btn btn-primary btn-block" type="submit">Log In</button></div><a href="#" class="forgot">Forgot your email or password?</a></form>
    </div>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/js/bootstrap.bundle.min.js"></script>
</body>

</html>


doctors-appointment/admin/proccess_login.php

<?php

include '../config.php';

// Now we check if the data from the login form was submitted, isset() will check if the data exists.
if (!isset($_POST['username'], $_POST['password'])) {
    // Could not get the data that should have been sent.
    exit('Please fill both the username and password fields!');
}

// Prepare our SQL, preparing the SQL statement will prevent SQL injection.
if ($stmt = $DB->prepare('SELECT id, password FROM auth_admin WHERE username = :username')) {
    
  
    
    // Bind parameters (s = string, i = int, b = blob, etc), in our case the username is a string so we use "s"

    $stmt->bindParam(":username", $_POST['username']);
    $stmt->execute();
    // Store the result so we can check if the account exists in the database.
    
    
   
    if ($stmt->rowCount() > 0) {
      $results =   $stmt->fetchAll();
    
   
        // Account exists, now we verify the password.
        // Note: remember to use password_hash in your registration file to store the hashed passwords.
        if (password_verify($_POST['password'],$results[0]['password']) == TRUE) {
            // Verification success! User has logged-in!
            // Create sessions, so we know the user is logged in, they basically act like cookies but remember the data on the server.
            session_regenerate_id();
            $_SESSION['loggedin'] = TRUE;
            $_SESSION['name'] = $_POST['username'];
            $_SESSION['id'] = $id;
            header('Location: dashboard');
        } else {
            // Incorrect password
          echo 'Incorrect username and/or password!';
        }
    } else {
        // Incorrect username
       echo 'Incorrect username and/or password!';
    }


    $DB = null;
}


Code is going long so please download zip file there is also mysql database file you can simple import in your phpmyadmin panel


Thanks I hope you find something ....

Download source code

Are you facing problems in understanding this article? download source code now