0% found this document useful (0 votes)
8 views4 pages

Table For Food Orders

The document outlines SQL commands to create a 'FoodOrders' table and populate 'MovieRooms' and 'FoodItems' with initial data. It also includes Python code for connecting to a MySQL database and a function to book movie tickets by checking room availability and updating seat counts. The code prompts users for room selection and the number of seats they wish to book.

Uploaded by

gopakishor1920
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)
8 views4 pages

Table For Food Orders

The document outlines SQL commands to create a 'FoodOrders' table and populate 'MovieRooms' and 'FoodItems' with initial data. It also includes Python code for connecting to a MySQL database and a function to book movie tickets by checking room availability and updating seat counts. The code prompts users for room selection and the number of seats they wish to book.

Uploaded by

gopakishor1920
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/ 4

-- Table for food orders

CREATE TABLE FoodOrders (OrderID INT


AUTO_INCREMENT PRIMARY KEY,BookingID INT,
FoodID INT,Quantity INT,TotalCost DECIMAL(6,
2),FOREIGN KEY
(BookingID) ,REFERENCESBookings(BookingID),
FOREIGN KEY (FoodID) REFERENCES
FoodItems(FoodID));
-- Populate movie rooms
INSERT INTO MovieRooms (RoomName,
AvailableSeats) VALUES ('Room 1', 100),('Room 2', 80),
('Room 3', 120),('Room 4', 150);

-- Populate food items


INSERT INTO FoodItems (FoodName, Price) VALUES
('Popcorn', 5.00),('Soda', 2.50),('Nachos', 3.50);

PYTHON CODE
import mysql.connector
from datetime import datetime
# MySQL connection
def connect_db():
return mysql.connector.connect()
host="localhost",
user="root", # Replace with your MySQL
username
password="1234", # Replace with your
MySQL password
database="TheatreBooking"

# Function to book movie tickets


def book_movie_tickets():
conn = connect_db()
cursor = conn.cursor()

# Display available movie rooms


cursor.execute("SELECT * FROM
MovieRooms")
rooms = cursor.fetchall()
print("Available movie rooms:")
for room in rooms:
print(f"Room ID: {room[0]}, Name:
{room[1]}, Available Seats: {room[2]}")

room_id = int(input("Enter the Room ID you


want to book: "))
customer_name = input("Enter your name:
")
seats = int(input("Enter the number of
seats to book:"))

# Check seat availability


cursor.execute("SELECT AvailableSeats
FROM MovieRooms WHERE RoomID = %s",
(room_id,))
result = cursor.fetchone()
if not result:
print("Invalid Room ID.")
elif seats > result[0]:
print("Sorry, not enough seats
available.")
else:
# Update available seats
cursor.execute("UPDATE MovieRooms
SET

You might also like