Guest User

SQL tinder

a guest
Jan 4th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.86 KB | None | 0 0
  1. import mysql.connector
  2. class Tinder:
  3.     def __init__(self):
  4.         self.conn = mysql.connector.connect(user="root",password="password",host="localhost",database="tinder")
  5.         self.mycursor=self.conn.cursor()
  6.         self.program_menu()
  7.  
  8.     def program_menu(self):
  9.         print("\n\n\tWELCOME TO TINDER\n\n")
  10.         print("""\n Enter 1 to login \n Enter 2 to Register \n Enter 3 to exit""")
  11.         choice=int(input("Enter your choice:\t"))
  12.  
  13.         if choice == 1:
  14.             self.user_login()
  15.         elif choice == 2:
  16.             self.user_register()
  17.         elif choice == 3:
  18.             print("THANK YOU! BYE!")
  19.         else:
  20.             print("Invalid Input. Try again!")
  21.             self.program_menu()
  22.  
  23.     def user_register(self):
  24.         name=input("Enter your name:\t")
  25.         email=input("Enter your email:\t")
  26.         password=input("Enter your password:\t")
  27.         gender=input("Enter your gender:\t")
  28.         city=input("Enter your city:\t")
  29.  
  30.         self.mycursor.execute("""
  31.        INSERT INTO `users`
  32.        (`name`,`email`,`password`,`gender`,`city`)
  33.        VALUES('%s','%s','%s','%s','%s')
  34.        """ %(name,email,password,gender,city))
  35.  
  36.         self.conn.commit()
  37.         self.program_menu()
  38.  
  39.     def user_login(self):
  40.         email=input("Enter your email:\t")
  41.         password=input("Enter your password:\t")
  42.  
  43.         self.mycursor.execute("""
  44.        SELECT * from `users` WHERE
  45.        `email` LIKE '%s' and `password` LIKE '%s'
  46.        """ %(email,password))
  47.  
  48.         user_list = self.mycursor.fetchall()
  49.         c=0
  50.         for i in user_list:
  51.             c=c+1
  52.             self.current_user_id=i[0]
  53.  
  54.         if c==1:
  55.             self.user_menu()
  56.         else:
  57.             print("Invalid Credentials")
  58.             self.program_menu()
  59.  
  60.  
  61.     def user_menu(self):
  62.         print("Success!!")
  63.  
  64. ob1=Tinder()
Add Comment
Please, Sign In to add comment