0% found this document useful (0 votes)
28 views3 pages

Fitness Centre Sys Text

Uploaded by

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

Fitness Centre Sys Text

Uploaded by

thiagarajan s
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

10/27/24, 3:43 PM fitness centre sys.

py

fitness centre sys.py

1 # 1. Establishes a connection to a MySQL database named "fitness" and checks if the


connection is successful.
2
3 # 2. Displays a main menu for users with three options:
4 # - Option 1: Create a new account.
5 # - Option 2: Log in to an existing account.
6 # - Option 3: Exit the program.
7
8 # 3. For account creation:
9 # - Collects user details (name, User ID, and password).
10 # - Inserts this information into the "Log_in" table in the database.
11
12 # 4. For login:
13 # - Prompts the user for their name, User ID, and password.
14 # - Validates the entered credentials by checking the "Log_in" table.
15
16 # 5. After successful login, provides additional options:
17 # - View employee details.
18 # - Update account details.
19 # - View all customer details.
20 # - Record a bill payment for a customer.
21 # - Exit the login session.
22
23 # 6. After each action, commits changes to the database where necessary and provides
appropriate messages to the user.
24
25 # 7. Closes the database cursor when exiting the program.
26
27
28 import mysql.connector as sql # Import MySQL connector for database connection
29
30 # Establish connection with MySQL database
31 conn = sql.connect(host="localhost", user="root", passwd="1234", database="fitness")
32 mycursor = conn.cursor()
33
34 # Check if the connection is successful
35 if conn.is_connected():
36 print("Connection With Database Established Successfully")
37 else:
38 print("Connection With Database Failed XXX")
39
40 # Welcome message for the fitness center
41 print("************************Welcome to DRAKE FITNESS CENTRE************************")
42
43 c1 = conn.cursor()
44 choice = 0
45
46 # Main menu loop; exits when user enters 3
47 while choice != 3:
48 print("1. CREATE YOUR ACCOUNT")
49 print("2. LOG IN")
50 print("3. EXIT")
localhost:49153/ad1aa87e-c98f-41a5-8602-959bf69db218/ 1/3
10/27/24, 3:43 PM fitness centre sys.py

51 choice = int(input("ENTER YOUR CHOICE:"))


52
53 # Option 1: Create a new user account
54 if choice == 1:
55 cust_name = input("Enter your name: ")
56 account_no = int(input("Enter your User ID: "))
57 password = int(input("Enter your Password: "))
58
59 # SQL command to insert new user data into Log_in table
60 SQL_insert = "insert into Log_in values ('" + cust_name + "'," + str(account_no) +
"," + str(password) + ")"
61 c1.execute(SQL_insert)
62 conn.commit() # Commit the changes to the database
63 print("//ACCOUNT CREATED//")
64
65 # Option 2: User login
66 if choice == 2:
67 print('\nEnter your Credentials')
68 cust_name = input('Enter your name: ')
69 account_no = int(input('Enter your User ID: '))
70 password = int(input('Enter your Password: '))
71
72 # Check login credentials by fetching all records from Log_in table
73 c1 = conn.cursor()
74 c1.execute('select * from Log_in')
75 data = c1.fetchall() # Fetch all data from Log_in table
76 count = c1.rowcount
77 c2 = 0 # Secondary choice variable for post-login actions
78
79 # Validate user credentials
80 for row in data:
81 if (cust_name in row) and (account_no in row) and (password in row):
82 print("\n\n************************WELCOME TO DRAKE FITNESS
CENTRE************************\n\n")
83 print('TO SEE EMPLOYEES DETAILS, press :1')
84 print('TO UPDATE DETAILS, press :2')
85 print('TO SEE Details of all the customers, press :3')
86 print('TO pay the bill, press :4')
87 print('TO EXIT, press :5')
88
89 # Execute post-login actions based on user choice
90 c2 = int(input("Enter your choice: "))
91
92 if c2 == 1:
93 # View all employee details
94 c1 = conn.cursor()
95 c1.execute('select * from log_in')
96 data = c1.fetchall()
97 count = c1.rowcount
98 print('Details of all employees:', count)
99 print("Details are arranged as Name/User ID/Password")
100 for row in data:
101 print(row)
102 conn.commit()

localhost:49153/ad1aa87e-c98f-41a5-8602-959bf69db218/ 2/3
10/27/24, 3:43 PM fitness centre sys.py

103 print("VISIT AGAIN")


104
105 elif c2 == 2:
106 # Update user details
107 print('\nTO UPDATE FILL THIS')
108 empName = input("Enter name: ")
109 update = input("Enter new name: ")
110
111 # SQL command to update the user's name
112 sqlFormula = "UPDATE log_in SET cust_name=%s WHERE cust_name = %s"
113 c1.execute(sqlFormula, (update, empName))
114 print('YOUR DETAILS ARE SUCCESSFULLY UPDATED')
115
116 elif c2 == 3:
117 # View all customer details
118 c1 = conn.cursor()
119 c1.execute('select * from customer_table')
120 data = c1.fetchall()
121 count = c1.rowcount
122 print('Details of all the Customers:', count)
123 for row in data:
124 print(row)
125 print("VISIT AGAIN")
126
127 elif c2 == 4:
128 # Record a bill payment
129 f_name = input("Enter your name: ")
130 price = int(input("Enter the amount to be paid: "))
131 weight = int(input("Enter your customer weight: "))
132 cust_name = input("Enter Customer Name: ")
133 phone_no = int(input("Enter Customer phone no: "))
134
135 # SQL command to insert a new record in the customer_table
136 SQL_insert = "insert into customer_table values('" + f_name + "'," +
str(price) + ",'" + str(weight) + "','" + cust_name + "'," + str(phone_no) + ")"
137 c1.execute(SQL_insert)
138 conn.commit()
139 print("Bill Recorded")
140
141 elif c2 == 5:
142 # Exit the program
143 print('THANK YOU FOR VISITING')
144 else:
145 print("Oops, something went wrong.....")
146
147 # Close the database cursor
148 c1.close()
149
150

localhost:49153/ad1aa87e-c98f-41a5-8602-959bf69db218/ 3/3

You might also like