fork download
  1. import mysql.connector
  2.  
  3. mycon = mysql.connector.connect(host='localhost', user='root', passwd='root')
  4. cursor = mycon.cursor()
  5. mycon.autocommit = True
  6. s1 = "create database railway"
  7. cursor.execute(s1)
  8. s1 = """create table railway(
  9. name varchar(100),
  10. phno varchar(15) primary key,
  11. age int(4),
  12. gender varchar(50),
  13. from_f varchar(100),
  14. to_t varchar(100),
  15. date_d varchar(20)
  16. )"""
  17. cursor.execute(s1)
  18. s1 = """create table user_accounts(
  19. fname varchar(100),
  20. lname varchar(100),
  21. user_name varchar(100),
  22. password varchar(100) primary key,
  23. phno varchar(15),
  24. gender varchar(50),
  25. dob varchar(50),
  26. age varchar(4)
  27. )"""
  28. cursor.execute(s1)
  29.  
  30. def menu():
  31. print('1.YES')
  32. print('2.NO')
  33.  
  34. ch = int(input('DO YOU WANT TO CONTINUE OR NOT:'))
  35. while ch == 1:
  36. print('WELCOME TO ONLINE RAILWAY RESERVATION SYSTEM')
  37. print('1.SIGN IN')
  38. print('2.SIGN UP')
  39. print('3.DELETE ACCOUNT')
  40. print('4.EXIT')
  41. ch1 = int(input('ENTER YOUR CHOICE:'))
  42. if ch1 == 1:
  43. a = checking()
  44. if a:
  45. print('WELCOME')
  46. main()
  47. else:
  48. continue
  49. elif ch1 == 2:
  50. a = checking_1()
  51. if a:
  52. main()
  53. else:
  54. print('PASSWORD ALREADY EXISTS')
  55. continue
  56. elif ch1 == 3:
  57. c = checking_2()
  58. if c:
  59. print('ACCOUNT DELETED')
  60. continue
  61. else:
  62. print('YOUR PASSWORD OR USER_NAME IS INCORRECT')
  63. continue
  64. elif ch1 == 4:
  65. print('THANK YOU')
  66. break
  67. else:
  68. print('ERROR 404:PAGE NOT FOUND')
  69. break
  70.  
  71. def main():
  72. print('1.yes')
  73. print('2.no')
  74. c = int(input("do you want to continue or not:"))
  75. while c == 1:
  76. print('''1.TICKET BOOKING
  77. 2.TICKET CHECKING
  78. 3.TICKET CANCELLING
  79. 4.ACCOUNT DETAILS
  80. 5.LOG OUT''')
  81. ch = int(input('enter your choice:'))
  82. if ch == 1:
  83. ticket_booking()
  84. elif ch == 2:
  85. ticket_checking()
  86. elif ch == 3:
  87. ticket_cancelling()
  88. elif ch == 4:
  89. checking_3()
  90. elif ch == 5:
  91. print('THANK YOU')
  92. break
  93. else:
  94. print('ERROR 404: ERROR PAGE NOT FOUND')
  95.  
  96. def ticket_booking():
  97. import mysql.connector
  98. mycon = mysql.connector.connect(host='localhost', user='root', passwd='root', database='railway')
  99. cursor = mycon.cursor()
  100. mycon.autocommit = True
  101. nm = input('enter your name:')
  102. phno = input('enter your phone number:')
  103. age = int(input('enter your age:'))
  104. print('''M=MALE
  105. F=FEMALE
  106. N=NOT TO MENTION''')
  107. gender = input('enter your gender:').upper()
  108. fr = input('enter your starting point:')
  109. to = input('enter your destination:')
  110. date1 = input('enter date(dd):')
  111. date2 = input('enter month(mm):')
  112. date3 = input('enter year(yyyy):')
  113. date = f"{date1}/{date2}/{date3}"
  114. a = {'M': 'MALE', 'F': 'FEMALE', 'N': 'NOT TO MENTION'}
  115. v = a[gender]
  116. s1 = f"insert into railway values ('{nm}', '{phno}', {age}, '{v}', '{fr}', '{to}', '{date}')"
  117. cursor.execute(s1)
  118. print('BOOKED SUCCESSFULLY')
  119.  
  120. def ticket_checking():
  121. import mysql.connector
  122. mycon = mysql.connector.connect(host='localhost', user='root', passwd='root', database='railway')
  123. cursor = mycon.cursor()
  124. mycon.autocommit = True
  125. print('1.yes')
  126. print('2.no')
  127. ch = int(input("do you want to continue or not:"))
  128. if ch == 1:
  129. phno = input('enter your phone number:')
  130. try:
  131. s1 = f"select * from railway where phno='{phno}'"
  132. cursor.execute(s1)
  133. data = cursor.fetchall()[0]
  134. a = ['NAME', 'PHONE NUMBER', 'AGE', 'GENDER', 'STARTING POINT', 'DESTINATION', 'DATE']
  135. for i, val in enumerate(data):
  136. print(f"{a[i]} ::: {val}")
  137. except:
  138. print('TICKET DOES NOT EXIST')
  139. elif ch == 2:
  140. print('THANK YOU')
  141. else:
  142. print('ERROR 404:PAGE NOT FOUND')
  143.  
  144. def ticket_cancelling():
  145. import mysql.connector
  146. mycon = mysql.connector.connect(host='localhost', user='root', passwd='root', database='railway')
  147. cursor = mycon.cursor()
  148. mycon.autocommit = True
  149. print('1.yes')
  150. print('2.no')
  151. ch = int(input("do you want to continue or not:"))
  152. if ch == 1:
  153. phno = input('enter your phone number:')
  154. s1 = f"delete from railway where phno='{phno}'"
  155. cursor.execute(s1)
  156. print('TICKET CANCELLED')
  157. elif ch == 2:
  158. print('THANK YOU')
  159. else:
  160. print('ERROR 404:PAGE NOT FOUND')
  161.  
  162. def checking_2():
  163. import mysql.connector
  164. mycon = mysql.connector.connect(host='localhost', user='root', passwd='root', database='railway')
  165. cursor = mycon.cursor()
  166. mycon.autocommit = True
  167. a = input('USER NAME:')
  168. b = input('PASSWORD:')
  169. try:
  170. s1 = f"select user_name from user_accounts where password='{b}'"
  171. cursor.execute(s1)
  172. data = cursor.fetchall()[0]
  173. if data[0] == a:
  174. print('IS THIS YOUR ACCOUNT')
  175. s1 = f"select fname, lname, phno, gender, dob, age from user_accounts where password='{b}'"
  176. cursor.execute(s1)
  177. data = cursor.fetchall()[0]
  178. x = ['FIRST NAME', 'LAST NAME', 'PHONE NUMBER', 'GENDER', 'DATE OF BIRTH', 'AGE']
  179. for i, val in enumerate(data):
  180. print(f"{x[i]} ::: {val}")
  181. print('1.yes')
  182. print('2.no')
  183. vi = int(input('enter your choice:'))
  184. if vi == 1:
  185. b1 = f"delete from user_accounts where password='{b}'"
  186. cursor.execute(b1)
  187. return True
  188. elif vi == 2:
  189. print('SORRY,RETRY')
  190. else:
  191. print('ERROR 404:PAGE NOT FOUND')
  192. else:
  193. return False
  194. except:
  195. print('ACCOUNT DOES NOT EXIST')
  196.  
  197. def checking_1():
  198. import mysql.connector
  199. mycon = mysql.connector.connect(host='localhost', user='root', passwd='root', database='railway')
  200. cursor = mycon.cursor()
  201. mycon.autocommit = True
  202. f = input("FIRST NAME:")
  203. l = input("LAST NAME:")
  204. a = input('USER NAME:')
  205. b = input('PASSWORD:')
  206. c = input('RE-ENTER YOUR PASSWORD:')
  207. ph = input("PHONE NUMBER:")
  208. print('M=MALE\nF=FEMALE\nN=NOT TO MENTION')
  209. gen = input('ENTER YOUR GENDER:')
  210. print("ENTER YOUR DATE OF BIRTH")
  211. d = input("DD:")
  212. o = input("MM:")
  213. p = input("YYYY:")
  214. dob = f"{d}/{o}/{p}"
  215. age = input('YOUR AGE:')
  216. v = {'m': 'MALE', 'f': 'FEMALE', 'n': 'NOT TO MENTION'}
  217. if b == c:
  218. try:
  219. c1 = f"insert into user_accounts values('{f}', '{l}', '{a}', '{b}', '{ph}', '{v[gen]}', '{dob}', '{age}')"
  220. cursor.execute(c1)
  221. print('WELCOME', f, l)
  222. return True
  223. except:
  224. print('PASSWORD ALREADY EXISTS')
  225. return False
  226. else:
  227. print('BOTH PASSWORDS ARE NOT MATCHING')
  228.  
  229. def checking():
  230. import mysql.connector
  231. mycon = mysql.connector.connect(host='localhost', user='root', passwd='root', database='railway')
  232. cursor = mycon.cursor()
  233. mycon.autocommit = True
  234. a = input('USER NAME:')
  235. b = input('PASSWORD:')
  236. try:
  237. s1 = f"select user_name from user_accounts where password='{b}'"
  238. cursor.execute(s1)
  239. data = cursor.fetchall()[0]
  240. if data[0] == a:
  241. c1 = f"select fname, lname from user_accounts where password='{b}'"
  242. cursor.execute(c1)
  243. data1 = cursor.fetchall()[0]
  244. data1 = f"{data1[0]} {data1[1]}"
  245. print('HII', data1)
  246. return True
  247. else:
  248. return False
  249. except:
  250. print('ACCOUNT DOES NOT EXIST')
  251.  
  252. def checking_3():
  253. import mysql.connector
  254. mycon = mysql.connector.connect(host='localhost', user='root', passwd='root', database='railway')
  255. cursor = mycon.cursor()
  256. mycon.autocommit = True
  257. a = input('USER NAME:')
  258. b = input('PASSWORD:')
  259. try:
  260. s1 = f"select user_name from user_accounts where password='{b}'"
  261. cursor.execute(s1)
  262. data = cursor.fetchall()[0]
  263. if data[0] == a:
  264. s1 = f"select fname, lname, phno, gender, dob, age from user_accounts where password='{b}'"
  265. cursor.execute(s1)
  266. data = cursor.fetchall()[0]
  267. x = ['FIRST NAME', 'LAST NAME', 'PHONE NUMBER', 'GENDER', 'DATE OF BIRTH', 'AGE']
  268. for i, val in enumerate(data):
  269. print(f"{x[i]} ::: {val}")
  270. else:
  271. return False
  272. except:
  273. print('ACCOUNT DOES NOT EXIST')
  274.  
  275. menu()
  276.  
Success #stdin #stdout 0.03s 25716KB
stdin
Standard input is empty
stdout
import mysql.connector

mycon = mysql.connector.connect(host='localhost', user='root', passwd='root')
cursor = mycon.cursor()
mycon.autocommit = True
s1 = "create database railway"
cursor.execute(s1)
s1 = """create table 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 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:
            print('WELCOME')
            main()
        else:
            continue
    elif ch1 == 2:
        a = checking_1()
        if a:
            main()
        else:
            print('PASSWORD ALREADY EXISTS')
            continue
    elif ch1 == 3:
        c = checking_2()
        if c:
            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
2.TICKET CHECKING
3.TICKET CANCELLING
4.ACCOUNT DETAILS
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
F=FEMALE
N=NOT TO MENTION''')
    gender = input('enter your 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 = f"{date1}/{date2}/{date3}"
    a = {'M': 'MALE', 'F': 'FEMALE', 'N': 'NOT TO MENTION'}
    v = a[gender]
    s1 = f"insert into railway values ('{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 = f"select * from railway where phno='{phno}'"
            cursor.execute(s1)
            data = cursor.fetchall()[0]
            a = ['NAME', 'PHONE NUMBER', 'AGE', 'GENDER', 'STARTING POINT', 'DESTINATION', 'DATE']
            for i, val in enumerate(data):
                print(f"{a[i]} ::: {val}")
        except:
            print('TICKET DOES NOT EXIST')
    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 = f"delete from railway where phno='{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 = f"select user_name from user_accounts where password='{b}'"
        cursor.execute(s1)
        data = cursor.fetchall()[0]
        if data[0] == a:
            print('IS THIS YOUR ACCOUNT')
            s1 = f"select fname, lname, phno, gender, dob, age from user_accounts where password='{b}'"
            cursor.execute(s1)
            data = cursor.fetchall()[0]
            x = ['FIRST NAME', 'LAST NAME', 'PHONE NUMBER', 'GENDER', 'DATE OF BIRTH', 'AGE']
            for i, val in enumerate(data):
                print(f"{x[i]} ::: {val}")
            print('1.yes')
            print('2.no')
            vi = int(input('enter your choice:'))
            if vi == 1:
                b1 = f"delete from user_accounts where password='{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')

def checking_1():
    import mysql.connector
    mycon = mysql.connector.connect(host='localhost', user='root', passwd='root', database='railway')
    cursor = mycon.cursor()
    mycon.autocommit = True
    f = input("FIRST NAME:")
    l = input("LAST NAME:")
    a = input('USER NAME:')
    b = input('PASSWORD:')
    c = input('RE-ENTER YOUR PASSWORD:')
    ph = input("PHONE NUMBER:")
    print('M=MALE\nF=FEMALE\nN=NOT TO MENTION')
    gen = input('ENTER YOUR GENDER:')
    print("ENTER YOUR DATE OF BIRTH")
    d = input("DD:")
    o = input("MM:")
    p = input("YYYY:")
    dob = f"{d}/{o}/{p}"
    age = input('YOUR AGE:')
    v = {'m': 'MALE', 'f': 'FEMALE', 'n': 'NOT TO MENTION'}
    if b == c:
        try:
            c1 = f"insert into user_accounts values('{f}', '{l}', '{a}', '{b}', '{ph}', '{v[gen]}', '{dob}', '{age}')"
            cursor.execute(c1)
            print('WELCOME', f, l)
            return True
        except:
            print('PASSWORD ALREADY EXISTS')
            return False
    else:
        print('BOTH PASSWORDS ARE NOT MATCHING')

def checking():
    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 = f"select user_name from user_accounts where password='{b}'"
        cursor.execute(s1)
        data = cursor.fetchall()[0]
        if data[0] == a:
            c1 = f"select fname, lname from user_accounts where password='{b}'"
            cursor.execute(c1)
            data1 = cursor.fetchall()[0]
            data1 = f"{data1[0]} {data1[1]}"
            print('HII', data1)
            return True
        else:
            return False
    except:
        print('ACCOUNT DOES NOT EXIST')

def checking_3():
    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 = f"select user_name from user_accounts where password='{b}'"
        cursor.execute(s1)
        data = cursor.fetchall()[0]
        if data[0] == a:
            s1 = f"select fname, lname, phno, gender, dob, age from user_accounts where password='{b}'"
            cursor.execute(s1)
            data = cursor.fetchall()[0]
            x = ['FIRST NAME', 'LAST NAME', 'PHONE NUMBER', 'GENDER', 'DATE OF BIRTH', 'AGE']
            for i, val in enumerate(data):
                print(f"{x[i]} ::: {val}")
        else:
            return False
    except:
        print('ACCOUNT DOES NOT EXIST')

menu()