0% found this document useful (0 votes)
8 views

CODEPROJECT

Uploaded by

ujavaljani
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

CODEPROJECT

Uploaded by

ujavaljani
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

import mysql.

connector

# Establish connection to the database


obj = mysql.connector.connect(
host="localhost",
user="root",
passwd="mukundan",
database="airlines"
)
mycursor = obj.cursor()

# Insert food items into the database


def populate_food_items():
food_data = [
('Pepsi', 150),
('Coffee', 70),
('Tea', 50),
('Water', 60),
('Milk Shake', 80),
('Chicken Burger', 160),
('Cheese Pizza', 70),
('Chicken Biryani', 300),
('Plain Rice', 80),
('Aloo Paratha', 120),
('Roti Sabji', 100),
('Omelette', 50)
]
for food in food_data:
mycursor.execute("INSERT INTO food_items (food_name, price) VALUES (%s, %s)",
food)
obj.commit()

# Manage luggage details


def luggage():
print("What do you want to do?")
print("1. Add Luggage")
print("2. Delete Luggage")
choice = int(input("Enter your choice: "))

if choice == 1:
luggage_type = input("Enter luggage type: ")
weight = int(input("Enter weight: "))
mycursor.execute("INSERT INTO luggage (luggage_type, weight) VALUES (%s, %s)",
(luggage_type, weight))
print("Luggage added successfully!")
elif choice == 2:
luggage_id = int(input("Enter luggage ID: "))
mycursor.execute("DELETE FROM luggage WHERE luggage_id = %s", (luggage_id,))
print("Luggage deleted successfully!")
else:
print("Invalid choice.")
obj.commit()

# Manage passenger records


def passenger():
print("What do you want to do?")
print("1. Add Passenger")
print("2. Update Passenger")
print("3. Delete Passenger")
print("4. Show Passenger Records")
choice = int(input("Enter your choice: "))

if choice == 1:
cust_name = input("Enter passenger name: ")
cont_no = int(input("Enter passenger contact number: "))
mycursor.execute("INSERT INTO customer_details (cust_name, cont_no) VALUES (%s,
%s)", (cust_name, cont_no))
print("Passenger added successfully!")
elif choice == 2:
cust_id = int(input("Enter passenger ID: "))
cust_name = input("Enter new passenger name: ")
cont_no = int(input("Enter new passenger contact number: "))
mycursor.execute("UPDATE customer_details SET cust_name = %s, cont_no = %s
WHERE cust_id = %s",
(cust_name, cont_no, cust_id))
print("Passenger updated successfully!")
elif choice == 3:
cust_id = int(input("Enter passenger ID: "))
mycursor.execute("DELETE FROM customer_details WHERE cust_id = %s", (cust_id,))
print("Passenger deleted successfully!")
elif choice == 4:
mycursor.execute("SELECT * FROM customer_details")
passengers = mycursor.fetchall()
print("Passenger Records:")
for passenger in passengers:
print(f"ID: {passenger[0]}, Name: {passenger[1]}, Contact: {passenger[2]}")
else:
print("Invalid choice.")
obj.commit()

# Manage food details


def food():
print("What do you want to do?")
print("1. Add New Items")
print("2. Update Price")
print("3. Delete Items")
choice = int(input("Enter your choice: "))

if choice == 1:
food_name = input("Enter food name: ")
food_price = int(input("Enter food price: "))
mycursor.execute("INSERT INTO food_items (food_name, price) VALUES (%s, %s)",
(food_name, food_price))
print("Food item added successfully!")
elif choice == 2:
food_id = int(input("Enter food ID: "))
new_price = int(input("Enter new price: "))
mycursor.execute("UPDATE food_items SET price = %s WHERE food_id = %s",
(new_price, food_id))
print("Food price updated successfully!")
elif choice == 3:
food_id = int(input("Enter food ID: "))
mycursor.execute("DELETE FROM food_items WHERE food_id = %s", (food_id,))
print("Food item deleted successfully!")
else:
print("Invalid choice.")
obj.commit()

# Display available food items


def food_items():
print("\nAvailable Foods:")
mycursor.execute("SELECT * FROM food_items")
items = mycursor.fetchall()
for item in items:
print(f"Food ID: {item[0]}, Name: {item[1]}, Price: {item[2]}")

# Display available flights


def flight_available():
print("\nAvailable Flights:")
mycursor.execute("SELECT * FROM flight_details")
flights = mycursor.fetchall()
for flight in flights:
print(f"Flight ID: {flight[0]}, Name: {flight[1]}, Departure: {flight[2]}, Destination: {flight[3]},
Day: {flight[4]}, Time: {flight[5]}")

# Book a ticket
def ticket_booking():
cust_name = input("Enter your name: ")
contact_no = int(input("Enter your contact number: "))
flight_id = int(input("Enter flight ID: "))
classtype = input("Enter class type (Business/Middle/Economic): ")

# Fetch the price based on the class type


mycursor.execute(f"SELECT {classtype.lower()}_price FROM flight_details WHERE flight_id
= %s", (flight_id,))
price = mycursor.fetchone()[0]

mycursor.execute("INSERT INTO customer_details (cust_name, cont_no) VALUES (%s,


%s)", (cust_name, contact_no))
customer_id = mycursor.lastrowid

mycursor.execute("""
INSERT INTO booking_details (cust_id, flight_id, classtype, price, date_of_booking)
VALUES (%s, %s, %s, %s, CURDATE())
""", (customer_id, flight_id, classtype, price))
print("Ticket booked successfully!")
obj.commit()

# Main user menu


def user():
while True:
print("\n1. Flight Details")
print("2. Food Details")
print("3. Book Ticket")
print("4. Exit")
choice = int(input("Enter your choice: "))

if choice == 1:
flight_available()
elif choice == 2:
food_items()
elif choice == 3:
ticket_booking()
elif choice == 4:
break
else:
print("Invalid choice.")

# Admin menu
def admin():
password = input("Enter admin password: ")
if password == "mukundan":
while True:
print("\n1. Manage Luggage")
print("2. Manage Food")
print("3. Manage Passengers")
print("4. Exit")
choice = int(input("Enter your choice: "))

if choice == 1:
luggage()
elif choice == 2:
food()
elif choice == 3:
passenger()
elif choice == 4:
break
else:
print("Invalid choice.")
else:
print("Incorrect password.")

# Main menu
def main_menu():
while True:
print("\n1. Admin")
print("2. User")
print("3. Exit")
choice = int(input("Enter your choice: "))

if choice == 1:
admin()
elif choice == 2:
user()
elif choice == 3:
break
else:
print("Invalid choice.")

if __name__ == "__main__":
main_menu()

You might also like