I have an error "name 'cust_id' is not defined"

def introduction():
print(’’’
COMPUTER SCIENCE PROJECT

                                             HOTEL RESERVATION SYSTEM

                                               MADE BY:AKARSH SINGH

                                                CLASS XII SCIENCE''')

import mysql.connector
def add():
mydb=mysql.connector.connect(host=“localhost”,user=“root”,passwd=“password”,database=“dbproject”)
mycur=mydb.cursor()
ch=‘y’
while ch==‘y’ or ch==‘Y’:
cust_id=int(input("\n Enter The Customer id: "))
cust_name=input("Enter the Customer name: ")
address=input("Enter the Address: ")
roomno=int(input("Enter The Room No: "))
mobileno=int(input("Enter The Mobile No: "))

    check_in=input("Enter the Check In Date (YYYY-MM-DD): ")
    check_out=input("Enter Check Out Date (YYYY-MM-DD): ")
    adv_payment=float(input("Enter the Advance Amt: "))

    room_type=int(input("Room Type:-\n 1:Suite(Rs.1500/day) \n 2:Delux(Rs.1000/day) \n 3:Standard(Rs.500/day)"))

    if room_type==1:
        room_type="Suite"
    elif room_type==2:
        room_type="Delux"
    elif room_type==3:
        room_type="Standard"
    else:
        print("Enter the correct Choice")

str="INSERT INTO hotel VALUES({},'{}','{}',{},{},'{}','{}',{},'{}')"

query=(str.format(cust_id,cust_name,address,roomno,mobileno,check_in,check_out,adv_payment,room_type))
mycur.execute(query)
mydb.commit()
print("\nCustomer record inserted\n")
ch=input("Want to Add more records(y/n): ")

def search():
mydb=mysql.connector.connect(host=“localhost”,user=“root”,passwd=“password”,database=“dbproject”)
mycur=mydb.cursor()
cno = int(input(“Enter the Customer id: “))
str = “Select * from hotel where cust_id={}”
query=str.format(cno)
print(”===========================================”)
mycur.execute(query)
myrec=mycur.fetchall()
for x in myrec:
cust_id = x[0]
cust_name = x[1]
address = x[2]
roomno = x[3]
mobileno = x[4]
check_in = x[5]
check_out = x[6]
adv_payment = x[7]
room_type = x[8]

print(cust_id,cust_name,address,roomno,mobileno,check_in,check_out,adv_payment,room_type)

def display():
mydb=mysql.connector.connect(host=“localhost”,user=“root”,passwd=“password”,database=“dbproject”)
mycur=mydb.cursor()
mycur.execute(“Select * from hotel”)
print("==========================================")
myrec=mycur.fetchall()

for x in myrec:
    cust_id = x[0]
    cust_name = x[1]
    address = x[2]
    roomno = x[3]
    mobileno = x[4]
    check_in = x[5]
    check_out = x[6]
    adv_payment = x[7]
    room_type = x[8]
print(cust_id,cust_name,address,roomno,mobileno,check_in,check_out,adv_payment,room_type)

def edit():
mydb=mysql.connector.connect(host=“localhost”,user=“root”,passwd=“password”,database=“dbproject”)
mycur=mydb.cursor()
mycur.execute(“Select * from hotel”)
print("==========================================")
print(“Before Updation”)
myrec=mycur.fetchall()

for x in myrec:
    cust_id = x[0]
    cust_name = x[1]
    address = x[2]
    roomno = x[3]
    mobileno = x[4]
    check_in = x[5]
    check_out = x[6]
    adv_payment = x[7]
    room_type = x[8]
print(cust_id,cust_name,address,roomno,mobileno,check_in,check_out,adv_payment,room_type)

cust_id=int(input("Enter Customer id whose record is to be Updated: "))
print("Enter the new data\n")
cust_name=input("Enter Customer name: ")
address=input("Enter Address: ")
roomno=int(input("Enter Room No: "))
mobileno=int(input("Enter Mobile No: "))
check_in=input("Check In Date (YYYY-MM-DD): ")
check_out=input("Check Out Date (YYYY-MM-DD): ")
adv_payment=float(input("Enter the Advance Amt paid: "))
room_type=int(input("Room Type:-(1:Suite 2:Deluxe 3:Common)"))

if room_type==1:
    room_type="Suite"
elif room_type==2:
    room_type="Deluxe"
elif room_type==3:
    room_type="Standard"
else:
    print("Enter your Choice")

mycur=mydb.cursor()
str="Update hotel set cust_name='{}',address='{}',roomno='{}',mobileno={},check_in='{}',check_out='{}',adv_payment={},room_type='{}'where cust_id={}"
query=str.format(cust_name,address,roomno,mobileno,check_in,check_out,adv_payment,room_type,cust_id)
mycur.execute(query)
mydb.commit()

mycur.execute("Select * from hotel")
print("==========================================")

print("After Update")
myrec=mycur.fetchall()

for x in myrec:
    cust_id = x[0]
    cust_name = x[1]
    address = x[2]
    roomno = x[3]
    mobileno = x[4]
    check_in = x[5]
    check_out = x[6]
    adv_payment = x[7]
    room_type = x[8]

print(cust_id,cust_name,address,roomno,mobileno,check_in,check_out,adv_payment,room_type)

def delete():
mydb=mysql.connector.connect(host=“localhost”,user=“root”,passwd=“password”,database=“dbproject”)
mycur=mydb.cursor()

mycur.execute("Select * from hotel")
print("==========================================")
print("Before Deletion")
myrec=mycur.fetchall()

for x in myrec:
    cust_id = x[0]
    cust_name = x[1]
    address = x[2]
    roomno = x[3]
    mobileno = x[4]
    check_in = x[5]
    check_out = x[6]
    adv_payment = x[7]
    room_type = x[8]
print(cust_id,cust_name,address,roomno,mobileno,check_in,check_out,adv_payment,room_type)

cust_id=int(input("Enter the Customer id: "))
str="Delete from hotel where cust_id={}"
query=str.format(cust_id)
mycur.execute(query)
mydb.commit()
mycur.execute(query)
print("Record Deleted")
mycur.execute("Select * from hotel")
print("==========================================")
print("After Deletion")
myrec=mycur.fetchall()

for x in myrec:
    cust_id = x[0]
    cust_name = x[1]
    address = x[2]
    roomno = x[3]
    mobileno = x[4]
    check_in = x[5]
    check_out = x[6]
    adv_payment = x[7]
    room_type = x[8]
print(cust_id,cust_name,address,roomno,mobileno,check_in,check_out,adv_payment,room_type)

def generate():
Tax=0

mydb=mysql.connector.connect(host="localhost",user="root",passwd="password",database="dbproject")
mycur=mydb.cursor()
cust_id=int(input("Enter the Customer id: "))
str="Select cust_id,cust_name,address,roomno,mobileno,check_in,check_out,adv_payment,room_type,dayofyear(check_out)-dayofyear(check_in) from hotel where cust_id={}"

query=str.format(cust_id)
print("==========================================")
mycur.execute(query)
myrec=mycur.fetchall()
for x in myrec:
    cust_id = x[0]
    cust_name = x[1]
    address = x[2]
    roomno = x[3]
    mobileno = x[4]
    check_in = x[5]
    check_out = x[6]
    adv_payment = x[7]
    room_type = x[8]
print("==========================================")
print("Hotel The Lalit")
print("500,South Extension")
print("Delhi")
print("==========================================")
print("Customer No",cust_id)
print("Customer Name",cust_name)
print("Customer Address",address)
print("==========================================")
print("Room No",roomno)
print("Mobile No",mobileno)
print("==========================================")
print("Check In",check_in)
print("Check Out",check_out)
print("Room Type",room_type)
print("==========================================")
print("No. of Days :",days)

if room_type=="Suite":
    price=1500
elif room_type=="Deluxe":
    price=1000
else:
    price=500

Total= daysprice
print(“Total”,Total)
print(“Advance”,adv_payment)
Tax=Total
0.10
print(“Tax: “,Tax)
net = float(adv_payment)-(float(Total)+float(Tax))
netamt = float(Total)+float(Tax)
print(“Net Amount”,netamt)
print(“Total Balance Payable to Customer”,net)
ch = ‘y’
while ch==‘y’ or ch==‘Y’:
print(”==========================================”)
print(“Menu”)
print(“1.To ADD New Record”)
print(“2.To Search a Record”)
print(“3.To Update the Record”)
print(“4.To Delete the Record”)
print(“5.To View all the Record”)
print(“6.To Generate the Report \n”)
print("==========================================")
ch=int(input(“Enter your choice: “))
Tax=0
if ch==1:
add()
elif ch==2:
search()
elif ch==3:
edit()
elif ch==4:
delete()
elif ch==5:
display()
elif ch==6:
generate()
print(”==========================================”)
ch=input("Want to display Main Menu(y/n): ")

You are trying to use the variable cust_id before giving a value. This may be because of a logical mistake, or because you got the indentation wrong – remember that if the variable is defined in a function, it is in local scope, meaning that it’s not accessible from the outside. If you can’t get it to work, try to edit your post to let it show proper indentation (read About the Users category) and we can debug it :wink: