[go: up one dir, main page]

0% found this document useful (0 votes)
5 views2 pages

Import Mysql

Uploaded by

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

Import Mysql

Uploaded by

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

import mysql.

connector
from datetime import date

# Connect to MySQL database


conn = mysql.connector.connect(
host="localhost",
user="root",
password="yourpassword",
database="hotel"
)
cursor = conn.cursor()

def show_available_rooms():
cursor.execute("SELECT * FROM rooms WHERE is_available = TRUE")
rooms = cursor.fetchall()
print("\nAvailable Rooms:")
for room in rooms:
print(f"Room ID: {room[0]}, Type: {room[1]}, Price: {room[2]}")

def check_in():
name = input("Enter customer name: ")
phone = input("Enter phone number: ")
show_available_rooms()
room_id = int(input("Enter Room ID to book: "))
checkin = input("Enter check-in date (YYYY-MM-DD): ")
checkout = input("Enter check-out date (YYYY-MM-DD): ")

cursor.execute("INSERT INTO customers (name, phone) VALUES (%s, %s)", (name, phone))
customer_id = cursor.lastrowid

cursor.execute("""
INSERT INTO bookings (customer_id, room_id, checkin_date, checkout_date)
VALUES (%s, %s, %s, %s)
""", (customer_id, room_id, checkin, checkout))

cursor.execute("UPDATE rooms SET is_available = FALSE WHERE room_id = %s", (room_id,))


conn.commit()
print("Room successfully booked.")

def check_out():
room_id = int(input("Enter room ID for checkout: "))
cursor.execute("UPDATE rooms SET is_available = TRUE WHERE room_id = %s", (room_id,))
conn.commit()
print("Checkout complete. Room is now available.")

def show_bookings():
cursor.execute("""
SELECT b.booking_id, c.name, r.room_type, b.checkin_date, b.checkout_date
FROM bookings b
JOIN customers c ON b.customer_id = c.customer_id
JOIN rooms r ON b.room_id = r.room_id
""")
bookings = cursor.fetchall()
print("\nAll Bookings:")
for b in bookings:
print(f"Booking ID: {b[0]}, Name: {b[1]}, Room: {b[2]}, Check-in: {b[3]}, Check-out: {b[4]}")

def main_menu():
while True:
print("\n--- Hotel Management Menu ---")
print("1. Show Available Rooms")
print("2. Check-In")
print("3. Check-Out")
print("4. Show All Bookings")
print("5. Exit")
choice = input("Select an option: ")

if choice == '1':
show_available_rooms()
elif choice == '2':
check_in()
elif choice == '3':
check_out()
elif choice == '4':
show_bookings()
elif choice == '5':
break
else:
print("Invalid option. Try again.")

main_menu()

cursor.close()
conn.close()

You might also like