How to develop Projects (AMS)Using PHP and Mysql Part 11

Rashmi Mishra
0

  Next Module: Consultation & Appointment Management

🎯 Purpose:

To allow users to schedule, manage, and attend consultations with astrologers, and for astrologers to manage their appointments.


 Functionalities to Include:

For Users:

  • 📅 Book an appointment with a selected astrologer
  • 🧾 Select consultation type (chat, call, in-person, etc.)
  •  Choose date and time slot
  • 📜 View consultation history
  •  Cancel a scheduled appointment (with conditions)

For Astrologers:

  • 🔔 View upcoming appointments
  •  Accept or reject bookings
  • ✏️ Update consultation status (Scheduled, Completed, Cancelled)

📁 Suggested Folder/File Structure:

/appointments/

── book_appointment.php        # Booking form for users

── my_appointments.php         # View user appointments

── astrologer_schedule.php     # Astrologer sets availability

── manage_appointments.php     # Astrologers manage bookings

── appointment_status.php      # Update consultation status


🧮 Suggested Database Tables:

1. appointments

CREATE TABLE appointments (

    id INT AUTO_INCREMENT PRIMARY KEY,

    user_id INT NOT NULL,

    astrologer_id INT NOT NULL,

    consultation_type ENUM('Chat', 'Call', 'In-Person') NOT NULL,

    appointment_date DATE NOT NULL,

    appointment_time TIME NOT NULL,

    status ENUM('Pending', 'Confirmed', 'Completed', 'Cancelled') DEFAULT 'Pending',

    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,

    FOREIGN KEY (user_id) REFERENCES users(id),

    FOREIGN KEY (astrologer_id) REFERENCES users(id)

);

2. availability (optional for astrologers)

CREATE TABLE availability (

    id INT AUTO_INCREMENT PRIMARY KEY,

    astrologer_id INT NOT NULL,

    available_date DATE NOT NULL,

    available_time TIME NOT NULL,

    status ENUM('Available', 'Booked') DEFAULT 'Available',

    FOREIGN KEY (astrologer_id) REFERENCES users(id)

);


📅 book_appointment.php

<?php

session_start();

include '../config.php'; 

if (!isset($_SESSION['user_id']) || $_SESSION['role'] != 'User') {

    header("Location: ../login.php");

    exit;

} 

if ($_SERVER['REQUEST_METHOD'] == 'POST') {

    $astrologer_id = $_POST['astrologer_id'];

    $consultation_type = $_POST['consultation_type'];

    $appointment_date = $_POST['appointment_date'];

    $appointment_time = $_POST['appointment_time'];

    $user_id = $_SESSION['user_id'];

 

    $query = "INSERT INTO appointments (user_id, astrologer_id, consultation_type, appointment_date, appointment_time)

              VALUES ('$user_id', '$astrologer_id', '$consultation_type', '$appointment_date', '$appointment_time')"; 

    if (mysqli_query($conn, $query)) {

        echo "Appointment booked successfully!";

    } else {

        echo "Error: " . mysqli_error($conn);

    }

}

?> 

<h2>Book an Appointment</h2>

<form method="POST">

    Astrologer ID: <input type="number" name="astrologer_id" required><br>

    Consultation Type:

    <select name="consultation_type" required>

        <option value="Chat">Chat</option>

        <option value="Call">Call</option>

        <option value="In-Person">In-Person</option>

    </select><br>

    Date: <input type="date" name="appointment_date" required><br>

    Time: <input type="time" name="appointment_time" required><br>

    <button type="submit">Book Appointment</button>

</form>


📜 my_appointments.php

<?php

session_start();

include '../config.php'; 

if (!isset($_SESSION['user_id']) || $_SESSION['role'] != 'User') {

    header("Location: ../login.php");

    exit;

} 

$user_id = $_SESSION['user_id'];

$result = mysqli_query($conn, "SELECT * FROM appointments WHERE user_id = '$user_id'"); 

echo "<h2>My Appointments</h2>";

while ($row = mysqli_fetch_assoc($result)) {

    echo "Astrologer ID: {$row['astrologer_id']} | Date: {$row['appointment_date']} | Time: {$row['appointment_time']} | Status: {$row['status']} ";

    if ($row['status'] == 'Pending' || $row['status'] == 'Confirmed') {

        echo " | <a href='cancel_appointment.php?id={$row['id']}'>Cancel</a>";

    }

    echo "<br>";

}

?>


cancel_appointment.php

<?php

session_start();

include '../config.php';

if (!isset($_SESSION['user_id']) || $_SESSION['role'] != 'User') {

    header("Location: ../login.php");

    exit;

}

 

$id = $_GET['id'];

$user_id = $_SESSION['user_id'];

 

$query = "UPDATE appointments SET status = 'Cancelled' WHERE id = '$id' AND user_id = '$user_id' AND status IN ('Pending', 'Confirmed')";

 

if (mysqli_query($conn, $query)) {

    echo "Appointment cancelled.";

} else {

    echo "Unable to cancel.";

}

?>


🗓️ astrologer_schedule.php

<?php

session_start();

include '../config.php'; 

if (!isset($_SESSION['user_id']) || $_SESSION['role'] != 'Astrologer') {

    header("Location: ../login.php");

    exit;

}

 

if ($_SERVER['REQUEST_METHOD'] == 'POST') {

    $date = $_POST['available_date'];

    $time = $_POST['available_time'];

    $astrologer_id = $_SESSION['user_id'];

 

    $query = "INSERT INTO availability (astrologer_id, available_date, available_time) VALUES ('$astrologer_id', '$date', '$time')";

    if (mysqli_query($conn, $query)) {

        echo "Availability set.";

    } else {

        echo "Error: " . mysqli_error($conn);

    }

}

?>

 

<h2>Set Your Availability</h2>

<form method="POST">

    Date: <input type="date" name="available_date" required><br>

    Time: <input type="time" name="available_time" required><br>

    <button type="submit">Set Availability</button>

</form>


🧾 manage_appointments.php

php

CopyEdit

<?php

session_start();

include '../config.php';

 

if (!isset($_SESSION['user_id']) || $_SESSION['role'] != 'Astrologer') {

    header("Location: ../login.php");

    exit;

}

 

$astrologer_id = $_SESSION['user_id'];

$result = mysqli_query($conn, "SELECT * FROM appointments WHERE astrologer_id = '$astrologer_id'");

 

echo "<h2>Manage Appointments</h2>";

while ($row = mysqli_fetch_assoc($result)) {

    echo "User ID: {$row['user_id']} | Date: {$row['appointment_date']} | Time: {$row['appointment_time']} | Status: {$row['status']} ";

 

    if ($row['status'] == 'Pending') {

        echo " | <a href='appointment_status.php?id={$row['id']}&status=Confirmed'>Accept</a>";

        echo " | <a href='appointment_status.php?id={$row['id']}&status=Cancelled'>Reject</a>";

    }

    echo "<br>";

}

?>


appointment_status.php

php

CopyEdit

<?php

session_start();

include '../config.php';

 

if (!isset($_SESSION['user_id']) || $_SESSION['role'] != 'Astrologer') {

    header("Location: ../login.php");

    exit;

}

 

$id = $_GET['id'];

$status = $_GET['status'];

 

if (in_array($status, ['Confirmed', 'Completed', 'Cancelled'])) {

    $query = "UPDATE appointments SET status = '$status' WHERE id = '$id'";

    if (mysqli_query($conn, $query)) {

        echo "Appointment updated to $status.";

    } else {

        echo "Update failed.";

    }

} else {

    echo "Invalid status.";

}

?>


All Set!
This creates:

  • User-side appointment booking and management.
  • Astrologer-side appointment management and availability.
  • Secure status updating with cancel/confirm logic.

💡 Next Steps:
If you want, I can also:

  • Add Bootstrap UI for pretty forms.
  • Add email notifications.
  • Write sample dashboards.

 

Post a Comment

0Comments

Post a Comment (0)