0% found this document useful (0 votes)
37 views7 pages

Movie Ticket Booking System

The document outlines a Movie Ticket Booking System developed using Python and MySQL. It includes functionalities for adding movies, viewing movies, booking tickets, viewing bookings, and canceling bookings, along with a basic admin login feature. The document provides details on database setup, connection setup, and the main menu implementation for user interaction.

Uploaded by

sanjay86680
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)
37 views7 pages

Movie Ticket Booking System

The document outlines a Movie Ticket Booking System developed using Python and MySQL. It includes functionalities for adding movies, viewing movies, booking tickets, viewing bookings, and canceling bookings, along with a basic admin login feature. The document provides details on database setup, connection setup, and the main menu implementation for user interaction.

Uploaded by

sanjay86680
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/ 7

Movie Ticket Booking System

Technologies Used
Python + MySQL
Functions Included
- Add Movies
- View Movies
- Book Tickets
- View Bookings
- Cancel Booking
- Admin Login (optional)
DATABASE SETUP
MySQL Table Creation (Run this in MySQL)
CREATE DATABASE movieticket;
USE movieticket;
CREATE TABLE movies (
movie_id INT AUTO_INCREMENT PRIMARY KEY,
title VARCHAR(100),
genre VARCHAR(50),
duration INT,
seats INT
);
CREATE TABLE bookings (
booking_id INT AUTO_INCREMENT PRIMARY KEY,
customer_name VARCHAR(100),
movie_id INT,
seats_booked INT,
FOREIGN KEY (movie_id) REFERENCES movies(movie_id)
);
🔹 1. Connection Setup (connection.py)
import mysql.connector
def connect():
return mysql.connector.connect(
host="localhost",
user="root",
password="",
database="movieticket"
)
🔹 2. Main Menu (main.py)
from modules import movie, booking
def main():
while True:
print("\n==== MOVIE TICKET BOOKING SYSTEM ====")
print("1. Add Movie")
print("2. View Movies")
print("3. Book Ticket")
print("4. View Bookings")
print("5. Cancel Booking")
print("6. Exit")
choice = input("Enter your choice: ")
if choice == '1':
movie.add_movie()
elif choice == '2':
movie.view_movies()
elif choice == '3':
booking.book_ticket()
elif choice == '4':
booking.view_bookings()
elif choice == '5':
booking.cancel_booking()
elif choice == '6':
print("Exiting system...")
break
else:
print("Invalid choice!")
main()
🔹 3. Movie Functions (modules/movie.py)
from connection import connect
def add_movie():
con = connect()
cur = con.cursor()
title = input("Enter movie title: ")
genre = input("Enter genre: ")
duration = int(input("Enter duration (minutes): "))
seats = int(input("Enter number of available seats: "))
cur.execute("INSERT INTO movies (title, genre, duration,
seats) VALUES (%s, %s, %s, %s)",
(title, genre, duration, seats))
con.commit()
print("Movie added successfully.")
def view_movies():
con = connect()
cur = con.cursor()
cur.execute("SELECT * FROM movies")
rows = cur.fetchall()
print("\n--- Available Movies ---")
for row in rows:
print(f"ID: {row[0]} | Title: {row[1]} | Genre: {row[2]} |
Duration: {row[3]} min | Seats: {row[4]}")
🔹 4. Booking Functions (modules/booking.py)
from connection import connect
def book_ticket():
con = connect()
cur = con.cursor()
customer_name = input("Enter your name: ")
movie_id = int(input("Enter Movie ID to book: "))
seats_booked = int(input("Enter number of seats: "))
cur.execute("SELECT seats FROM movies WHERE movie_id=
%s", (movie_id,))
available = cur.fetchone()
if available and available[0] >= seats_booked:
cur.execute("INSERT INTO bookings (customer_name,
movie_id, seats_booked) VALUES (%s, %s, %s)",
(customer_name, movie_id, seats_booked))
cur.execute("UPDATE movies SET seats = seats - %s
WHERE movie_id = %s",
(seats_booked, movie_id))
con.commit()
print("Booking confirmed!")
else:
print("Not enough seats available.")
def view_bookings():
con = connect()
cur = con.cursor()
cur.execute("""
SELECT b.booking_id, b.customer_name, m.title,
b.seats_booked
FROM bookings b JOIN movies m ON b.movie_id =
m.movie_id
""")
rows = cur.fetchall()
print("\n--- Booking Records ---")
for row in rows:
print(f"Booking ID: {row[0]} | Customer: {row[1]} | Movie:
{row[2]} | Seats: {row[3]}")
def cancel_booking():
con = connect()
cur = con.cursor()
booking_id = int(input("Enter Booking ID to cancel: "))
cur.execute("SELECT movie_id, seats_booked FROM
bookings WHERE booking_id = %s", (booking_id,))
data = cur.fetchone()
if data:
movie_id, seats_to_restore = data
cur.execute("DELETE FROM bookings WHERE booking_id
= %s", (booking_id,))
cur.execute("UPDATE movies SET seats = seats + %s
WHERE movie_id = %s",
(seats_to_restore, movie_id))
con.commit()
print("Booking cancelled and seats restored.")
else:
print("Booking not found.")

You might also like