0% found this document useful (0 votes)
12 views20 pages

Food Ordering System Python Project

The document outlines a Python project for a food ordering system that utilizes a MySQL database to manage data related to employees, customers, food items, and orders. It includes functionalities for adding and viewing records through a command-line interface, with defined tables for each data category. The code structure includes functions for data entry and retrieval, along with a menu system for user interaction.

Uploaded by

Umang
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)
12 views20 pages

Food Ordering System Python Project

The document outlines a Python project for a food ordering system that utilizes a MySQL database to manage data related to employees, customers, food items, and orders. It includes functionalities for adding and viewing records through a command-line interface, with defined tables for each data category. The code structure includes functions for data entry and retrieval, along with a menu system for user interaction.

Uploaded by

Umang
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

GRM SR SEC PUBLIC SCHOOL

PROJECT FILE

Computer Science
2023-24

Abhinav 12th B
26648997
Food Order System Python Project
Here is a Python Project for managing a database related to a food
ordering system. It uses the MySQL database system to store
information about employees, customers, food items, and food
orders. The code defines tables for Employee, Customer, Food and
OrderFood. It allows you to add records to these tables and view
them. Here is an overview of the code’s functionality and structure:

Importing necessary modules: The code imports the connector module


for working with the MySQL database.

Database connection: It establishes a connection to a MySQL database


hosted on the local machine with the username “root” and password
“admin”.

Creating tables: The code creates several tables within the “food1”
database, including Employee, Customer, Food and OrderFood.
These tables define the structure of the data that will be stored in the
database.

Functions for data entry

Customer(): Allows you to add a customer’s information to the


“Customer” table
Employee(): Allows you to add an employee’s information to the
“Employee” table
Food(): Lets you add food item details to the “Food” table
OrderFood(): Allows you to add an order for food to the
“OrderFood” table.

View function: The View() function lets you search for and display
records based on different search criteria, such as employee details,
customer details, food items, or food orders.
MenuSet function: This function displays a menu with options to add
records or view data. You can choose an option by entering a
corresponding number.

RunAgain function: After performing an action, the script asks if you


want to run the program again. If you choose “Y,” the menu is
displayed again.

To use the script, you would execute it in a Python environment with


the necessary MySQL connector library installed. It provides a simple
command-line interface for interacting with the database.

The following pages contain

the code for this file


import os

import platform

import [Link]

mydb = [Link](host="localhost", user="Sam", password="password01")

# creating DB

mycursor = [Link]()

[Link]("create database if not exists food1")

[Link]("use food1")

# creating Tables

# Define the Employee table

[Link]("""

CREATE TABLE IF NOT EXISTS Employee (

Emp_id INT AUTO_INCREMENT PRIMARY KEY,

ename VARCHAR(255) NOT NULL,

emp_g VARCHAR(10),

eage INT,

emp_phone BIGINT,

pwd VARCHAR(255)

""")

# Define the Customer table

[Link]("""

CREATE TABLE IF NOT EXISTS Customer (

c_id INT AUTO_INCREMENT PRIMARY KEY,

name VARCHAR(255) NOT NULL,

cphone BIGINT,

payment INT,

pstatus VARCHAR(20),

email VARCHAR(255),

orderid INT,

date DATE

""")

# Define the Food table

[Link]("""

CREATE TABLE IF NOT EXISTS Food (

Food_id INT AUTO_INCREMENT PRIMARY KEY,

Foodname VARCHAR(255) NOT NULL,

Food_size VARCHAR(20),

prize INT

""")

# Define the OrderFood table

[Link]("""

CREATE TABLE IF NOT EXISTS OrderFood (

Orderf_id INT AUTO_INCREMENT PRIMARY KEY,

C_id INT,

Emp_id INT,

Food_id INT,

Food_qty INT,

Total_price INT

""")

# Define the fee table

[Link]("""

CREATE TABLE IF NOT EXISTS fee (

roll INT AUTO_INCREMENT PRIMARY KEY,

feedeposit INT,

month VARCHAR(10)

""")

# main COde

def Customer():

L = []

c_id = int(input("Enter the customer ID number: "))

[Link](c_id)

name = input("Enter the Customer Name: ")

[Link](name)

cphone = int(input("Enter customer phone number: "))

[Link](cphone)

payment = int(input("Enter payment method (1 for credit card, 2 for Debit Card): "))

[Link](payment)

pstatus = input("Enter the payment status: ")

[Link](pstatus)

email = input("Enter the email id: ")

[Link](email)

orderid = input("Enter orderid: ")

[Link](orderid)

date = input("Enter the Date: ")

[Link](date)

cust = tuple(L)

sql = "INSERT INTO Customer (c_id, name, cphone, payment, pstatus, email, orderid, date)

VALUES (%s, %s, %s, %s, %s, %s, %s, %s)"

[Link](sql, cust)

[Link]()

def Employee():

L = []

Emp_id = int(input("Enter the Employee id: "))

[Link](Emp_id)

ename = input("Enter the Employee Name: ")

[Link](ename)

emp_g = input("Enter Employee Gender: ")

[Link](emp_g)

eage = int(input("Enter Employee age: "))

[Link](eage)

emp_phone = int(input("Enter employee phone number: "))

[Link](emp_phone)

pwd = input("Enter the password: ")

[Link](pwd)

EMP = tuple(L) # Convert the list to a tuple

sql = "INSERT INTO Employee (Emp_id, ename, emp_g, eage, emp_phone, pwd) VALUES

(%s, %s, %s, %s, %s, %s)"

[Link](sql, EMP)

[Link]()

def Food():

L = []

Food_id = int(input("Enter the Food id: "))

[Link](Food_id)

Foodname = input("Enter the Food Name: ")

[Link](Foodname)

Food_size = input("Enter Food size: ")

[Link](Food_size)

prize = int(input("Enter Prize of Food: "))

[Link](prize)

Food = tuple(L)

sql = "INSERT INTO Food (Food_id, Foodname, Food_size, prize) VALUES

(%s, %s, %s, %s)"

[Link](sql, Food)

[Link]()

def OrderFood():

L = []

Orderf_id = int(input("Enter the Food Order id: "))

[Link](Orderf_id)

C_id = int(input("Enter the Customer id: "))

[Link](C_id)

Emp_id = int(input("Enter Employee id: "))

[Link](Emp_id)

Food_id = int(input("Enter Food id: "))

[Link](Food_id)

Food_qty = int(input("Enter Qty: "))

[Link](Food_qty)

Total_price = int(input("Enter Total_price: "))

[Link](Total_price)

OrderFood = tuple(L) # Convert the list to a tuple

sql = "INSERT INTO OrderFood (Orderf_id, C_id, Emp_id, Food_id, Food_qty, Total_price)

VALUES (%s, %s, %s, %s, %s, %s)"

[Link](sql, OrderFood)

[Link]()

def View():

print("Select the search criteria: ")

print("1. Employee")

print("2. Customer")

print("3. Food")

print("4. Order Food")

ch = int(input("Enter the choice 1 to 4: "))

if ch == 1:

Emp_id = int(input("Enter Employee ID: "))

sql = "SELECT * FROM Employee WHERE Emp_id = %s"

[Link](sql, (Emp_id,))

res = [Link]()

for x in res:

print(x)

elif ch == 2:

c_name = input("Enter Customer Name: ")

sql = "SELECT * FROM Customer WHERE name = %s"

[Link](sql, (c_name,))

res = [Link]()

for x in res:

print(x)

elif ch == 3:

sql = "SELECT * FROM Food"

[Link](sql)

res = [Link]()

for x in res:

print(x)

elif ch == 4:

food_id = int(input("Enter Food ID: "))

sql = "SELECT * FROM OrderFood WHERE Food_id = %s"

[Link](sql, (food_id,))

res = [Link]()

for x in res:

print(x)

def MenuSet():

print("Enter 1 to Add Employee")

print("Enter 2 to Add Customer details")

print("Enter 3 to Add Food Details")

print("Enter 4 for Food Order")

print("Enter 5 to view Food booking")

try:

userInput = int(input("Please Select an above option: "))

except ValueError:

exit("\nHey! That's Not A Number")

else:

print("\n")

if userInput == 1:

Employee()

elif userInput == 2:

Customer()

elif userInput == 3:

Food()

elif userInput == 4:

OrderFood()

elif userInput == 5:

View()

else:

print("Enter correct choice. . .")

def runAgain():

runAgn = input("\nWant to run again? (Y/N): ")

while [Link]() == 'y':

if [Link]() == "Windows":

[Link]("cls")

else:

[Link]("clear")

MenuSet()

runAgn = input("\nWant to run again? (Y/N): ")

MenuSet()

runAgain()

print("Good Bye... HAVE A NICE DAY”)


The following pages contain

the output for the code presented

in the previous pages


Output:
Output:
Output:
Output:
Output:
Output:
Output:
Output:
Thank

You

Common questions

Powered by AI

The primary tables used in the food ordering system's database include the Employee, Customer, Food, and OrderFood tables. The Employee table stores data such as employee ID, name, gender, age, phone number, and password . The Customer table contains information such as customer ID, name, phone number, payment method, payment status, email, and order ID . The Food table records details like food ID, name, size, and price . Finally, the OrderFood table tracks food order details like order ID, customer ID, employee ID, food ID, quantity, and total price .

The 'View' function in the food ordering system serves the role of allowing users to search and display existing records based on certain criteria. Users can view information about employees, customers, food items, or food orders by selecting the corresponding option. This feature enhances user experience by providing easy and direct access to specific data without having to manually navigate or query the database, thereby saving time and ensuring efficiency in retrieving information .

The 'MenuSet' function enhances usability by providing a straightforward menu interface where users can select different operations like adding employee or customer details and placing orders by entering corresponding numbers . This design reduces the complexity for users by allowing easy navigation and interaction with the system. The 'RunAgain' function further enhances usability by automatically prompting users to continue operations without needing to restart the entire application. It thus facilitates a seamless, continuous interaction flow, improving user satisfaction and reducing downtime .

The dependency on the MySQL connector is crucial for the operation of this food ordering system as it facilitates communication between the Python script and the MySQL database. Without it, the system would be unable to perform essential operations such as creating tables, inserting records, or retrieving data from the database . However, this dependency also ties the system to environments where the MySQL connector is available and properly configured, potentially limiting portability and ease of deployment across different systems. Additionally, any updates or changes to the connector or MySQL versions might require corresponding updates in the application code to maintain compatibility and functionality .

The system's approach to handling user passwords is suboptimal as it stores them directly in the database without hashing or encryption, exposing user credentials to security risks if the database is breached . To improve this, it is recommended to implement password hashing using algorithms like bcrypt or Argon2, which ensure that even if the database is compromised, the passwords remain secure. Moreover, incorporating a salt with each password before hashing would provide additional security by making each hash unique, reducing vulnerability to dictionary or rainbow table attacks. Employing secure authentication frameworks can also strengthen password management .

The 'Add' methods such as Customer(), Employee(), Food(), and OrderFood() ensure data integrity by prompting users for specific required fields for each table, thus minimizing the chance of missing data entries. Each function collects related information and then inserts it into the corresponding database table using SQL statements, committing the entries to the database to ensure the changes are saved and consistent . Furthermore, they use input validation by requiring IDs and phone numbers to be integer values, which helps maintain the accuracy and type consistency of the data entries .

The current system could benefit from implementing object-oriented programming (OOP) principles by introducing classes for the main entities (e.g., Employee, Customer, Food, Order) with methods related to each entity's operations. This encapsulation would lead to a more modular codebase, allowing for easier maintenance and scalability by isolating functionalities specific to each class . Using OOP, developers could also leverage inheritance to extend or modify system functionality without major changes across the codebase, improving adaptability to future needs. Additionally, OOP encourages abstraction and reusability, which could reduce redundancy and highlight the core operations needed for database manipulations, thus streamlining development processes .

If the 'commit' operation is not properly implemented in the system's functions, it could lead to significant issues with data consistency. Without explicitly committing transactions after successful data operations, there is a risk that intended changes won't be saved in the database, which may result in lost or inconsistent data. For instance, failing to commit after new data entries could mean that records appear to be added during the session but aren't actually stored, leading to discrepancies between expected and actual data states . This could compromise the reliability of any reports or analysis based on such data, affecting decision-making and operational efficiency .

The database connection setup presents several security implications. Firstly, the use of plain-text credentials (username and password) in the script is a risk factor, as it could expose sensitive information to unauthorized users . Additionally, hardcoding these credentials makes it difficult to change them without altering the code, increasing the potential for human error or oversight. The setup does not appear to include encryption or use any secure authentication methods, such as OAuth, which would add layers of security by safeguarding the information exchanged between the application and the database . Ideally, credentials should be stored and accessed securely, possibly using environment variables or a secure vaulting mechanism.

Improvements to the input validation process could include enforcing stricter validation rules and offering feedback for incorrect inputs. For instance, data entries such as emails and phone numbers could be validated with regex patterns to ensure they match expected formats, thereby reducing input errors . Inputs like payment methods that currently accept integers could be converted to more intuitive and error-proof dropdown menus or radio buttons to avoid confusion. Adding validations to check for existing IDs before adding redundant entries would also enhance data integrity. Moreover, implementing exception handling for inputs could provide users with informative feedback in case of errors, guiding them towards successful data entry .

You might also like