OBJECTIVE
To make a Python-based application
integrated with MySQL for managing
FLIGHT TICKET BOOKINGS
CONTENTS
1. Acknowledgement
2. Certificate
3. Hardware and Software Required
4. Introduction
5. Python Source Code
6. Output
7. Explanation of Code
8. Bibliography
ACKNOWLEDGEMENT
I would like to extend my sincere and heartfelt
obligation towards all those who have helped me in
making this project. Without their active guidance,
help, cooperation and encouragement, I would not
have been able to present the project on time.
I am extremely thankful and pay my sincere gratitude
to my teacher Mr. Devendra Singh Yadav for his
valuable guidance and support for completion this
project.
I extend my sincere gratitude to my Principal Mr.
Rakesh Upadhyay for the moral support extended
during tenure of this project.
I also acknowledge with a deep sense of reverence,
my gratitude towards my parents, other faculty
members of the school and friends for their valuable
suggestions given to me in completing the project.
CERTIFICATE
This is to certify that the project work titled
FLIGHT TICKET BOOKING is the bonafide
work of SAUMIL SARASWAT of Class XII-A of
PURANCHANDRA VIDYANIKETAN,
KANPUR as a part of Computer Science
Project work for Class XII AISSCE, practical
examination of the central board of secondary
education in the year 2024-2025. It is further
certified that this project is the individual work
of candidate.
Teacher’s sign Examiner’s Sign
HARDWARES AND
SOFTWARES REQUIRED
HARDWARES
• Desktop/Laptop
• Mobile Phone
SOFTWARES
• Python 3.13 (Latest Version)
• MySQL
• MySQL-Connector-Python
INTRODUCTION
The Flight Booking System is a Python-based
application designed to streamline the process
of managing flight ticket bookings. Integrated
with a MySQL database, this system allows users
to perform essential operations such as booking
tickets, checking ticket status, canceling bookings,
and updating passenger details. With a user-
friendly menu-driven interface, the system
ensures smooth interaction and efficient data
handling. Key features include secure database
connectivity using parameterized queries,
modular code structure for easy maintenance,
and real-time data updates. This project
demonstrates the practical application of Python
and MySQL in building reliable, interactive
systems for real-world scenarios.
PYTHON SOURCE CODE
CONNECTING DATABASE AND ESTABLISHING A MENU SYSTEM
import mysql.connector
# Connecting to the MySQL database
conn = mysql.connector.connect(
host="localhost",
user=“root",
password=“pcvn",
database="FlightDB"
)
# Create a cursor object
cursor = conn.cursor()
# Function to create the table
def initialize_table():
cursor.execute('''
CREATE TABLE IF NOT EXISTS tickets (
TicketID INT PRIMARY KEY AUTO_INCREMENT,
PassengerID INT,
Name VARCHAR(100),
SeatNo VARCHAR(10),
FlightNo VARCHAR(20),
ArrivalLocation VARCHAR(100),
DepartureLocation VARCHAR(100),
ArrivalTime DATETIME,
DepartureTime DATETIME)
''')
conn.commit()
# Function to book a ticket
def book_ticket():
passenger_id = int(input("Enter Passenger ID: "))
name = input("Enter Passenger Name: ")
seat_no = input("Enter Seat Number: ")
flight_no = input("Enter Flight Number: ")
arrival_location = input("Enter Arrival Location: ")
departure_location = input("Enter Departure Location: ")
arrival_time = input("Enter Arrival Time (YYYY-MM-DD
HH:MM:SS): ")
departure_time = input("Enter Departure Time (YYYY-MM-DD
HH:MM:SS): ")
# Insert the ticket details into the tickets table
query = '''
INSERT INTO tickets (PassengerID, Name, SeatNo, FlightNo,
ArrivalLocation, DepartureLocation, ArrivalTime, DepartureTime)
VALUES (%s, %s, %s, %s, %s, %s, %s, %s)
'''
cursor.execute(query, (passenger_id, name, seat_no, flight_no,
arrival_location, departure_location, arrival_time,
departure_time))
conn.commit()
print(f"Ticket booked successfully! Ticket ID: {cursor.lastrowid}")
# Function to check ticket status
def check_ticket_status():
ticket_id = int(input("Enter Ticket ID: "))
# Retrieve the ticket details
query = "SELECT * FROM tickets WHERE TicketID = %s"
cursor.execute(query, (ticket_id,))
result = cursor.fetchone()
if result:
print("\nTicket Details:")
print(f"Ticket ID: {result[0]}, Passenger ID: {result[1]}, Name: {result[2]},
Seat No: {result[3]}, Flight No: {result[4]}")
print(f"Arrival Location: {result[5]}, Departure Location: {result[6]}")
print(f"Arrival Time: {result[7]}, Departure Time: {result[8]}")
else:
print("Ticket not found!")
# Function to cancel a ticket
def cancel_ticket():
ticket_id = int(input("Enter Ticket ID to cancel: "))
# Delete the ticket
query = "DELETE FROM tickets WHERE TicketID = %s"
cursor.execute(query, (ticket_id,))
conn.commit()
if cursor.rowcount > 0:
print("Ticket cancelled successfully!")
else:
print("Ticket not found!")
# Function to change ticket details (name and seat number only)
def change_details():
ticket_id = int(input("Enter Ticket ID to modify: "))
new_name = input("Enter new Name: ")
new_seat_no = input("Enter new Seat Number: ")
# Update the ticket details
query = "UPDATE tickets SET Name = %s, SeatNo = %s WHERE TicketID = %s"
cursor.execute(query, (new_name, new_seat_no, ticket_id))
conn.commit()
if cursor.rowcount > 0:
print("Details updated successfully!")
else:
print("Ticket not found!")
# Menu-driven application for flight booking system
def main():
initialize_table()
while True:
print("\n--- Flight Booking System ---")
print("1. Book a Ticket")
print("2. Check Ticket Status")
print("3. Cancel a Ticket")
print("4. Change Ticket Details (Name and Seat No)")
print("5. Exit")
try:
choice = int(input("Enter your choice: "))
if choice == 1:
book_ticket()
elif choice == 2:
check_ticket_status()
elif choice == 3:
cancel_ticket()
elif choice == 4:
change_details()
elif choice == 5:
print("Exiting the application.")
break
else:
print("Invalid choice! Please try again.")
except ValueError:
print("Invalid input! Please enter a number.")
# Run the main program
if __name__ == "__main__":
try:
main()
finally:
# Close the cursor and the connection
cursor.close()
conn.close()
OUTPUT
--- Flight Booking System Menu ---
1.Book a Ticket
2. Check Ticket Status
3. Cancel a Ticket
4. Change Passenger Details
5. Exit
Enter your choice:
#Booking a Ticket
Enter Passenger ID:101
Enter Name: John Doe
Enter Seat Number: A12
Enter Flight Number: FL123
Enter Arrival Location: New York
Enter Departure Location: Los Angeles
Enter Arrival Time (YYYY-MM-DD HH:MM:SS): 2024-12-25
15:30:00
Enter Departure Time (YYYY-MM-DD HH:MM:SS): 2024-12-25
12:00:00
Ticket booked successfully! Your Ticket ID is: 1
#Checking Ticket Status
Enter Ticket ID: 1
--- Ticket Details ---
Passenger ID: 101
Name: John Doe
Seat Number: A12
Flight Number: FL123
Arrival Location: New York
Departure Location: Los Angeles
Arrival Time: 2024-12-25 15:30:00
Departure Time: 2024-12-25 12:00:00
#If Ticket ID is invalid:
Enter Ticket ID: 999
Ticket not found!
#Canceling a Ticket
Enter Ticket ID: 1
Ticket with ID 1 has been canceled.
#Changing Passenger Details
Enter Ticket ID: 1
Enter new Name: Jane Doe
Enter new Seat Number: B14
Details updated successfully!
#Exiting the Program:
Exiting the application. Thank you!
EXPLANATION OF CODE
The Flight Booking System is a Python-based
application integrated with a MySQL database to
manage flight ticket operations efficiently. The
code connects to a MySQL database named
`FlightDB` and performs CRUD operations (Create,
Read, Update, Delete) on a table called `tickets`.
Users can interact with the system through a menu-
driven interface to book tickets, check ticket
statuses, cancel bookings, or modify passenger
details (name and seat number). Each function uses
SQL queries such as `INSERT`, `SELECT`, `UPDATE`,
and `DELETE` to handle data securely, leveraging
parameterized queries to prevent SQL injection.
The program maintains a clear and modular
structure, ensuring easy navigation and future
scalability, making it a robust example of
integrating Python with relational databases for
real-world applications.
BIBLIOGRAPHY
• w3schools.com
• geeksforgeeks.org