SOURCE CODE
import mysql.connector
# Establishing connection to the database
connection = mysql.connector.connect(
host="localhost",
user="admin_user",
password="securepass",
database="restaurant_db"
cursor = connection.cursor()
# Display menu function
def display_menu():
query = "SELECT * FROM menu"
cursor.execute(query)
dishes = cursor.fetchall()
if dishes:
print("\n---- Available Dishes ----\n")
for dish in dishes:
print(f"Dish ID: {dish[0]}, Name: {dish[1]} (Type: {dish[3]}), Price: {dish[2]}")
else:
print("No dishes available at the moment.")
print("\n")
user_choice = int(input("Would you like to place an order? (1 for Yes, 2 to Exit): "))
if user_choice == 1:
place_order()
else:
print("Returning to the main menu...")
# Place an order function
def place_order():
dish_id = int(input("Enter the Dish ID of the item you want to order: "))
quantity = int(input("Enter the quantity: "))
customer_name = input("Enter your name: ")
phone_number = input("Enter your phone number: ")
address = input("Enter your address: ")
query = f"SELECT * FROM menu WHERE ID = {dish_id}"
cursor.execute(query)
dish = cursor.fetchone()
if dish:
total_price = dish[2] * quantity
order_query = (
"INSERT INTO customer_orders (dish_id, quantity, customer_name, phone_number, address,
total_price) "
"VALUES (%s, %s, %s, %s, %s, %s)"
cursor.execute(order_query, (dish_id, quantity, customer_name, phone_number, address,
total_price))
connection.commit()
print(f"\nThank you {customer_name}, your order for {dish[1]} has been placed successfully!")
print(f"Total Price: {total_price}")
else:
print("Invalid Dish ID. Please try again.")
# Cancel an order function
def cancel_order():
phone_number = input("Enter your phone number to cancel the order: ")
query = f"DELETE FROM customer_orders WHERE phone_number = '{phone_number}'"
cursor.execute(query)
connection.commit()
print("Your order has been canceled successfully.")
# Feedback function
def feedback():
name = input("Enter your name: ")
feedback_text = input("Write your feedback about us: ")
query = "INSERT INTO feedback (customer_name, feedback) VALUES (%s, %s)"
cursor.execute(query, (name, feedback_text))
connection.commit()
print("Thank you for your feedback!")
# Main menu
def main_menu():
while True:
print("\n--- Main Menu ---")
print("1. View Menu")
print("2. Cancel Order")
print("3. Leave Feedback")
print("4. Exit")
choice = int(input("Enter your choice: "))
if choice == 1:
display_menu()
elif choice == 2:
cancel_order()
elif choice == 3:
feedback()
elif choice == 4:
print("Thank you for visiting!")
break
else:
print("Invalid choice. Please try again.")
# Start the application
main_menu()
SQL
MENU
CUSTOMERS ORDERS
CUSTOMER FEEDBACK
OUTPUT
--- Main Menu ---
1. View Menu
2. Cancel Order
3. Leave Feedback
4. Exit
Enter your choice: 1
---- Available Dishes ----
Dish ID: 1, Name: Shahi Paneer (Type: Veg), Price: 650.00
Dish ID: 2, Name: Masala Dosa (Type: Veg), Price: 150.00
Dish ID: 3, Name: Chicken Tikka (Type: Non-Veg), Price: 800.00
Dish ID: 4, Name: Chicken Tandoori (Type: Non-Veg), Price: 750.00
Dish ID: 5, Name: Chole Bhature (Type: Veg), Price: 400.00
Dish ID: 6, Name: Paneer Makhni (Type: Veg), Price: 550.00
Dish ID: 7, Name: Steamed Momo (Type: Veg), Price: 160.00
Dish ID: 8, Name: Chicken Momo (Type: Non-Veg), Price: 250.00
Dish ID: 9, Name: Coffee (Type: Beverage), Price: 80.00
Dish ID: 10, Name: Mango Shake (Type: Beverage), Price: 170.00
Would you like to place an order? (1 for Yes, 2 to Exit): 1
Enter the Dish ID of the item you want to order: 3
Enter the quantity: 2
Enter your name: John Doe
Enter your phone number: 1234567890
Enter your address: 123 Main St, City
Thank you John Doe, your order for Chicken Tikka has been placed successfully!
Total Price: 1600.00
--- Main Menu ---
1. View Menu
2. Cancel Order
3. Leave Feedback
4. Exit
Enter your choice: 3
Enter your name: John Doe
Write your feedback about us: Great service and delicious food!
Thank you for your feedback!
--- Main Menu ---
1. View Menu
2. Cancel Order
3. Leave Feedback
4. Exit
Enter your choice: 2
Enter your phone number to cancel the order: 1234567890
Your order has been canceled successfully.
--- Main Menu ---
1. View Menu
2. Cancel Order
3. Leave Feedback
4. Exit
Enter your choice: 4
Thank you for visiting!