0% found this document useful (0 votes)
117 views4 pages

Railway Source Code

This Python code defines functions for an online railway reservation system with the following capabilities: 1. It connects to a MySQL database called "railway" that contains tables for user accounts and ticket bookings. 2. The menu function displays options to sign in, sign up, delete an account, or exit. It calls additional functions for authentication, account management and the main system features. 3. The main function displays options for ticket booking, checking, cancelling, viewing account details, or logging out. It calls corresponding functions to implement each system feature. 4. Functions are defined to implement ticket booking, checking, cancelling and account deletion by performing queries on the MySQL tables.

Uploaded by

Asmit Upadhyay
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
117 views4 pages

Railway Source Code

This Python code defines functions for an online railway reservation system with the following capabilities: 1. It connects to a MySQL database called "railway" that contains tables for user accounts and ticket bookings. 2. The menu function displays options to sign in, sign up, delete an account, or exit. It calls additional functions for authentication, account management and the main system features. 3. The main function displays options for ticket booking, checking, cancelling, viewing account details, or logging out. It calls corresponding functions to implement each system feature. 4. Functions are defined to implement ticket booking, checking, cancelling and account deletion by performing queries on the MySQL tables.

Uploaded by

Asmit Upadhyay
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

import mysql.

connector

mycon = mysql.connector.connect(host='localhost', user='root', passwd='root')


cursor = mycon.cursor()
mycon.autocommit = True
s1 = "CREATE DATABASE IF NOT EXISTS railway"
cursor.execute(s1)

s1 = """CREATE TABLE IF NOT EXISTS railway (


name VARCHAR(100),
phno VARCHAR(15) PRIMARY KEY,
age INT(4),
gender VARCHAR(50),
from_f VARCHAR(100),
to_t VARCHAR(100),
date_d VARCHAR(20)
)"""
cursor.execute(s1)

s1 = """CREATE TABLE IF NOT EXISTS user_accounts (


fname VARCHAR(100),
lname VARCHAR(100),
user_name VARCHAR(100),
password VARCHAR(100) PRIMARY KEY,
phno VARCHAR(15),
gender VARCHAR(50),
dob VARCHAR(50),
age VARCHAR(4)
)"""
cursor.execute(s1)

def menu():
print('1. YES')
print('2. NO')
ch = int(input('DO YOU WANT TO CONTINUE OR NOT: '))

while ch == 1:
print('WELCOME TO ONLINE RAILWAY RESERVATION SYSTEM')
print('1. SIGN IN')
print('2. SIGN UP')
print('3. DELETE ACCOUNT')
print('4. EXIT')
ch1 = int(input('ENTER YOUR CHOICE: '))

if ch1 == 1:
a = checking()
if a == True:
print('WELCOME')
main()
else:
continue
elif ch1 == 2:
a = checking_1()
if a == True:
main()
else:
print('PASSWORD ALREADY EXISTS')
continue
elif ch1 == 3:
c = checking_2()
if c == True:
print('ACCOUNT DELETED')
continue
else:
print('YOUR PASSWORD OR USER_NAME IS INCORRECT')
continue
elif ch1 == 4:
print('THANK YOU')
break
else:
print('ERROR 404: PAGE NOT FOUND')
break

def main():
print('1. YES')
print('2. NO')
c = int(input("DO YOU WANT TO CONTINUE OR NOT: "))
while c == 1:
print(' 1. TICKET BOOKING')
print(' 2. TICKET CHECKING')
print(' 3. TICKET CANCELLING')
print(' 4. ACCOUNT DETAILS')
print(' 5. LOG OUT')
ch = int(input('ENTER YOUR CHOICE: '))
if ch == 1:
ticket_booking()
elif ch == 2:
ticket_checking()
elif ch == 3:
ticket_cancelling()
elif ch == 4:
checking_3()
elif ch == 5:
print('THANK YOU')
break
else:
print('ERROR 404: ERROR PAGE NOT FOUND')

def ticket_booking():
import mysql.connector
mycon = mysql.connector.connect(host='localhost', user='root', passwd='root',
database='railway')
cursor = mycon.cursor()
mycon.autocommit = True
nm = input('enter your name: ')
phno = input('enter your phone number: ')
age = int(input('enter your age: '))
print(' M=MALE', '\n', 'F=FEMALE', '\n', 'N=NOT TO MENTION')
gender = input('enter your gender: ')
gender = gender.upper()
fr = input('enter your starting point: ')
to = input('enter your destination: ')
date1 = input('enter date(dd): ')
date2 = input('enter month(mm): ')
date3 = input('enter year(yyyy): ')
date = date1 + "/" + date2 + "/" + date3
a = {'M': 'MALE', 'F': 'FEMALE', 'N': 'NOT TO MENTION'}
v = a[gender]
s1 = "INSERT INTO railway VALUES ('{}', '{}', {}, '{}', '{}', '{}',
'{}')".format(nm, phno, age, v, fr, to, date)
cursor.execute(s1)
print('BOOKED SUCCESSFULLY')

def ticket_checking():
import mysql.connector
mycon = mysql.connector.connect(host='localhost', user='root', passwd='root',
database='railway')
cursor = mycon.cursor()
mycon.autocommit = True
print('1. YES')
print('2. NO')
ch = int(input("DO YOU WANT TO CONTINUE OR NOT: "))
if ch == 1:
phno = input('enter your phone number: ')
try:
s1 = "SELECT * FROM railway WHERE phno = '{}'".format(phno)
cursor.execute(s1)
data = cursor.fetchall()
if data:
data = data[0]
a = ['NAME', 'PHONE NUMBER', 'AGE', 'GENDER', 'STARTING POINT',
'DESTINATION', 'DATE']
print(a[0], '::::', data[0].upper())
print(a[1], '::::', data[1])
print(a[2], '::::', data[2])
print(a[3], '::::', data[3].upper())
print(a[4], '::::', data[4].upper())
print(a[5], '::::', data[5].upper())
print(a[6], '::::', data[6])
else:
print('TICKET DOES NOT EXISTS')
except:
print('ERROR: An error occurred while checking the ticket.')
elif ch == 2:
print('THANK YOU')
else:
print('ERROR 404: PAGE NOT FOUND')

def ticket_cancelling():
import mysql.connector
mycon = mysql.connector.connect(host='localhost', user='root', passwd='root',
database='railway')
cursor = mycon.cursor()
mycon.autocommit = True
print('1. YES')
print('2. NO')
ch = int(input("DO YOU WANT TO CONTINUE OR NOT: "))
if ch == 1:
phno = input('enter your phone number: ')
s1 = "DELETE FROM railway WHERE phno = '{}'".format(phno)
cursor.execute(s1)
print('TICKET CANCELLED')
elif ch == 2:
print('THANK YOU')
else:
print('ERROR 404: PAGE NOT FOUND')
def checking_2():
import mysql.connector
mycon = mysql.connector.connect(host='localhost', user='root', passwd='root',
database='railway')
cursor = mycon.cursor()
mycon.autocommit = True
a = input('USER NAME: ')
b = input('PASSWORD: ')

try:
s1 = "SELECT user_name FROM user_accounts WHERE password = '{}'".format(b)
cursor.execute(s1)
data = cursor.fetchall()

if len(data) > 0 and data[0][0] == a:


print('\nIS THIS YOUR ACCOUNT')
s1 = "SELECT user_name FROM user_accounts WHERE password =
'{}'".format(b)
c1 = "SELECT fname, lname FROM user_accounts WHERE password =
'{}'".format(b)
cursor.execute(c1)
data1 = cursor.fetchall()[0]
data1 = list(data1)
data1 = data1[0] + ' ' + data1[1]
cursor.execute(s1)
data = cursor.fetchall()[0]
data = list(data)
if data[0] == a:
x = ['FIRST NAME', 'LAST NAME', 'PHONE NUMBER', 'GENDER', 'DATE OF
BIRTH', 'AGE']
s1 = "SELECT fname, lname, phno, gender, dob, age FROM
user_accounts WHERE password = '{}'".format(b)
cursor.execute(s1)
data = cursor.fetchall()[0]
data = list(data)
print(x[0], ':::', data[0])
print(x[1], ':::', data[1])
print(x[2], ':::', data[2])
print(x[3], ':::', data[3])
print(x[4], ':::', data[4])
print(x[5], ':::', data[5])
print('\n1. YES')
print('2. NO')
vi = int(input('ENTER YOUR CHOICE: '))
if vi == 1:
b1 = "DELETE FROM user_accounts WHERE password =
'{}'".format(b)
cursor.execute(b1)
return True
elif vi == 2:
print('SORRY, RETRY')
else:
print('ERROR 404: PAGE NOT FOUND')
else:
return False
except:
print('ACCOUNT DOES NOT EXIST')

menu()

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy