Railway Reservation - Edited
Railway Reservation - Edited
S.No. Topic
1 Certificate
2 Acknowledgement
4 Introduction
6 MySQL Database
7 Outputs
8 References
HARDWARES AND SOFTWARES
REQUIRED
HARDWARES
1. Desktop / Laptop
2. Mobile Phone
SOFTWARES
1. Python (latest version)
2. MySQL
3. Python Connector
Module
INTRODUCTION
Objectives of the Project
1. Administrative Empowerment, the core objectives of our
project are multi-faceted, addressing the intricate needs of
both administrators and passengers within the railway
ecosystem.
Administrative Functions
The Admin Panel, a focal point of the system, equips
administrators with indispensable tools:
User Interaction
User Login: The system provides a secure login interface
for registered users, requiring user ID and password for
access.
Forgot User ID: Users can retrieve forgotten user IDs
through their registered email addresses, enhancing user
experience and reducing barriers to access.
Forgot User ID
The `forgot_user_id()` function provides a mechanism for
users to retrieve their registered user IDs via email
verification, ensuring a smooth user experience.
Train Search
The `Train_Search()` function allows users to search for
trains based on origin and destination, providing detailed
information about available trains.
Book Tickets
The `Book_Ticket(uid)` function simulates the ticket booking
process, allowing users to select trains, classes, and
passengers for reservation.
Cancel Tickets
The `Cancel_Ticket()` function facilitates the cancellation of
booked tickets, showcasing the system's ability to handle
modifications to user bookings.
i. #FORGET USER ID
def forgot_user_id():
dbo=con.connect(host="localhost",user="root",password="admin",database="train_
reservation")
co=dbo.cursor()
email=input("Enter your registered email: ")
co.execute("select user_id from user where email_id like '{}'".format(email))
emel=co.fetchall()
for i in emel:
print("Your user_id is: ",(i[0]))
print("******************AccessGranted**************")
print(" ---------------------------------------------------------- ")
admin_panel()
else:
print("*************ACCESS NOT GRANTED ENTER CORRECTPASSWORD**********")
print(" ---------------------------------------------------------- ")
adminpassword()
i. #ADD TRAIN
def add_train():
dbo=con.connect(host="localhost",user="root",password="admin",database="train_
reservation")
co=dbo.cursor()
print(" ------------------------------------------------------------------- ")
a=int(input("Enter train no: "))
b=input("Enter train name: ")
c=input("Enter train origin: ")
d=input("Enter train destination: ")
e=int(input("Enter train journey distance: "))
g=input("Enter train journey time: ")
h=int(input("Enter no of seats in AC: "))
i=int(input("Enter no of seats in SL: "))
j=int(input("Enter no of seats in GEN: "))
k=int(input("Enter price of AC: "))
l=int(input("Enter price of SL: "))
m=int(input("Enter price of GEN: "))
n=input("Enter days available: ")
print(" ------------------------------------------------------------------- ")
co.execute("insert into train_schedule values
({},'{}','{}','{}',{},'{}',{},{},{},{},{},{},'{}')".format(a,b,c,d,e,g,h,i,j,k,l,m,n))
print("*********You have added a new train details successfully************")
dbo.commit()
ii. #UPDATE TRAIN TABLE
def update_details():
dbo=con.connect(host="localhost",user="root",password="admin",database=
"train_reservation")
co=dbo.cursor()
print(" ------------------------------------------------------------------ ")
print("******Welcome to update train system******")
while True:
# To Update train no
if x==1:
print(" ----------------------------------------------------------- ")
print("**********YOU ARE GOING TO UPDATE TRAIN NO***********")
tname=input("Enter train name whose no you want to update: ")
tno=int(input("Enter updated train no: "))
co.execute("update train_schedule set train_no={} where
train_name='{}'".format(tno,tname))
print("*******UPDATED SUCCESSFULLY********")
print(" ----------------------------------------------------------- ")
dbo.commit()
return
# To Update train name
elif x==2:
print(" ------------------------------------------------------------------ ")
print("**********YOU ARE GOING TO UPDATE TRAIN NAME***********")
tno=int(input("Enter train no whose name you want to update: "))
tname=input("Enter updated train name: ")
co.execute("update train_schedule set train_name='{}' where
train_no={}".format(tname,tno))
print("*******UPDATED SUCCESSFULLY********")
print(" ------------------------------------------------------------------ ")
dbo.commit()
return
return
elif x==14:
print("**********YOU ARE NOW OUT OF UPDATE DETAILS SECTION***********")
break
return
v. #CANCEL TRAIN
def cancel_train():
dbo=con.connect(host="localhost",user="root",password="admin",database=
"train_reservation")
co=dbo.cursor()
ct=int(input("enter train no which you want to cancel: "))
co.execute("delete from train_schedule where train_no={}".format(ct))
dbo.commit()
print("*********** Train cancelled Successfully ****************")
vi. #ADMIN PANEL OPTIONS
def admin_panel():
while True:
try:
print(" --------------------------------------------------------------- ")
print("******Welcome to admin panel******")
print("1. Add train")
print("2. Update details")
print("3. Cancel Train")
print("4. Log out")
opt=int(input("Choose your option: "))
if opt==1:
add_train()
elif opt==2:
update_details()
elif opt==3:
cancel_train()
elif opt==4:
print("**********You are out of admin panel***********")
print(" --------------------------------------------------------- ")
main_menu()
except InvalidOptionError as e:
print(f"Error: {e}")
except:
print("**********Choose a correct option***********")
print(" ------------------------------------------------------------------- ")
#PASSENGER PANEL FUNCTIONALITIES
def Train_Search():
dbo=con.connect(host="localhost",user="root",password="admin",database="train_
reservation")
co=dbo.cursor()
o=input("Enter your origin: ")
d=input("Enter your destination: ")
co.execute("select * from train_schedule where origin like '%{}%' and
destination like '%{}%'".format(o,d))
a=co.fetchall()
for i in a:
print("Train no.: ",a[0][0])
print("Train name: ",a[0][1])
print("Origin: ",a[0][2])
print("Destination: ",a[0][3])
print("Journey distance: ",a[0][4])
print("Available days: ",a[0][12])
print("total time: ",a[0][5])
print("Seats in ac1: ",a[0][6])
print("Seats in sl: ",a[0][7])
print("Seats in GEN: ",a[0][8])
print("Fare of ac1: ",a[0][9])
print("Fare of sl: ",a[0][10])
print("Fare of gen: ",a[0][11])
dbo.commit()
#BOOK TICKETS
def Book_Ticket(uid):
dbo=con.connect(host="localhost",user="root",password="admin",database=
"train_reservation")
co=dbo.cursor()
print("THIS IS OUR ALL TRAINS AVAILABLE \n ---------------------------------------------
------------------------")
op="select train_no,train_name,origin,destination from train_schedule"
co.execute(op)
r=co.fetchall()
columns=[i[0] for i in co.description]
print(tabulate(r,headers=columns,tablefmt="fancy_grid")) 311
print(" ------------------------------------------------------------------ \n\n")
trainno=int(input("Enter your Train no: "))
tcktno=int(input("Enter no of seats you want to book: "))
print("1. AC TICKET")
print("2. SL TICKET")
print("3. GEN TICKET")
typ=int(input("Enter your choice of class: "))
if typ==1:
a=co.execute("select ac1_fare from train_schedule where
train_no={}".format(trainno))
b=co.fetchall()
print(b[0][0])
elif typ==2:
a=co.execute("select sl_fare from train_schedule where
train_no={}".format(trainno))
b=co.fetchall()
print(b[0][0])
elif typ==3:
a=co.execute("select gen_fare from train_schedule where
train_no={}".format(trainno))
b=co.fetchall()
print(b[0][0])
for i in range (tcktno):
cus1=input("Enter customer name: ")
age=int(input("Enter your age: "))
print("--------------- For gender M=Male, F=Female, O=Other ------------------")
gender=input("Enter your gender: ")335.
j=random.randint(100000,999999)
print("Your PNR no is: ",j)
cnf="Confirmed"
p=b[0][0]
co.execute("insert into booked_tickets values
('{}',{},{},'{}',{},'{}',{},'{}')".format(uid,j,trainno,cus1,age,gender,p,cnf))
p=b[0][0]
amt=tcktno*p
print("Your total ticket price is: ",amt)
dbo.commit()
def Cancel_Ticket():
dbo=con.connect(host="localhost",user="root",password="admin",database=
"train_reservation")
co=dbo.cursor()
pnr=int(input("enter pnr no. you want to cancel: "))
co.execute("delete from booked_tickets where pnr_no={}".format(pnr))
dbo.commit()
print("*********** Your ticket cancelled Successfully ****************")
i. #PASSENGER PANEL
def passenger_panel(uid):
dbo=con.connect(host="localhost",user="root",password="admin",database=
"train_reservation")
co=dbo.cursor()
while True:
print(" ------------------------------------------------------------------ ")
print("******Welcome to passenger panel******")
print("1. Train Search")
print("2. Book Ticket")
print("3. Cancel Ticket")
print("4. Log out")
choic=int(input("Enter your choice to use: "))
if choic==1:
Train_Search()
elif choic==2:
Book_Ticket(uid)
elif choic==3:
Cancel_Ticket()
elif choic==4:
main_menu()
print("*****You are successfully logged out of Passenger panel*****")
print(" ------------------------------------------------------------------- ")
#Panel functions
def main_menu():
print(" --------------------------------------------------- ")
print("********WELCOME TO TRAIN RESERVATION SYSTEM********")
print("1. Admin panel")
print("2. Passenger panel")
print("3. Exit")
ch=int(input("Enter your choice: "))
while True:
if ch==1:
adminpassword()
elif ch==2:
user_panel()
elif ch==3:
print("***** Thank You for using reservation system*****")
print(" ------------------------------------------------------------------- ")
break
main_menu()
MYSQL
DATABASE
TRAIN TABLE:
PASSENGER LIST :
USER DETAILS :
BOOKED_TICKETS:
OUTPUT
TRAIN RESERVATION MAIN PAGE:
THE ADMIN LOGIN PANEL:
CANCEL TICKET:
BOOKING TICKETS :
SEARCH TRAIN:
REFERENCES
2. PYTHON
HTTPS://www.PYTHON.ORG/
3. MYSQL
HTTPS://WWW. MYSQL.COM/