Karansahu
Karansahu
import mysql.connector
db1 = None
def connect():
global db1
db1 = mysql.connector.connect(host="localhost",user="root",
password="root",
database = "library"
)
#FUNCTION TO LOGIN
def login():
#print("-" * 40)
print("\t Library Management System")
#print("-" * 40)
print("\t LOGIN")
un = input("Enter User Name : ")
pw = input("Enter Password : ")
q = "select * from users where username = %s and passw = %s"
val = (un,pw)
c2 = db1.cursor()
c2.execute(q,val)
res = c2.fetchall()
print("-" * 50)
if len(res) == 0:
print("Invalid User Name or Password ")
print("-" * 50)
return False
else:
print("Access Granted !!!")
print("-" * 50)
return True
#FUNCTION TO DELETE MEMBER
def delMember():
print("-" * 40)
print("\tDELETING A MEMBER")
print("-" * 40)
mid = input("Enter Member Id : ")
cursor1 = db1.cursor()
q = "delete from member where mid=" + mid
cursor1.execute(q)
db1.commit()
print("Member Deleted Successfully")
cursor1 = db1.cursor()
q = "insert into member values (%s,%s,%s,%s)"
val = (mid,name,phone,email)
cursor1.execute(q,val)
db1.commit()
print("Member Added Successfully")
cursor1 = db1.cursor()
q = "insert into book values (%s,%s,%s,%s,%s)"
val = (bid,title,author,pub,cost)
cursor1.execute(q,val)
db1.commit()
print("Book Added Successfully")
def issueBook():
bid = input("Enter the book id to be issued : ")
q ="select * from issue where bookid='" + bid +"'"
cursor1 = db1.cursor()
cursor1.execute(q)
res = cursor1.fetchall()
if len(res)== 0:
mid = input("Enter the member id : ")
doi = input("Enter the date of issue : ")
q = "insert into issue (mid,bookid,dateofissue) values(%s,%s,%s)"
data = (mid,bid,doi)
cursor1.execute(q,data)
db1.commit()
print("-" * 40)
print(" Book Issued Successfully")
print("-" * 40)
else:
print("-" * 40)
print(" Sorry ! The Book is not available")
print("-" * 40)
connect()
print("Connected")
print(" WELCOME TO LIBRARY")
if login():
while True:
print("-" * 50)
print("\t CHOOSE AN OPERATION ")
print("-" * 50)
print("Press 1 - Add a New Member")
print("Press 2 - Delete an Existing Member")
print("Press 3 - Show all Members")
print("Press 4 - Add a New Book")
print("Press 5 - Delete an Existing Book")
print("Press 6 - Show all Books")
print("Press 7 - Issue a Book")
print("Press 8 - Return a Book")
print("Press 9 - Show Issued Books")
print("Press 10 - Show Returned Books")
print("Press 11 - Quit")
ch = int(input("Enter Your Choice : "))
if ch == 1:
addMember()
elif ch == 2:
delMember()
elif ch == 3:
showMembers()
elif ch == 4:
addBook()
elif ch == 5:
delBook()
elif ch == 6:
showBooks()
elif ch == 7:
issueBook()
elif ch == 8:
returnBook()
elif ch == 9:
showIssued()
elif ch == 10:
showReturned()
elif ch == 11:
break