Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
9 views

Library Management IP source code

This document is a Python script for a Library Management System that connects to a MySQL database. It allows users to manage books, including adding, removing, issuing, and depositing books, as well as viewing available and issued books. The system includes a login feature and handles user authentication with a simple user interface in the console.

Uploaded by

dhongibaba4282
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)
9 views

Library Management IP source code

This document is a Python script for a Library Management System that connects to a MySQL database. It allows users to manage books, including adding, removing, issuing, and depositing books, as well as viewing available and issued books. The system includes a login feature and handles user authentication with a simple user interface in the console.

Uploaded by

dhongibaba4282
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
You are on page 1/ 9

import mysql.

connector
mydb=mysql.connector.connect(host='localhost',user='root',passwd='Y
ogi1234@')
mycursor=mydb.cursor()
print("""
------------------------------------
************************************
------------------------------------

WELCOME TO LIBRARY MANAGEMENT SYSTEM

------------------------------------
************************************
------------------------------------
""")
#CREATING DATABASE
mycursor.execute("create database if not exists Library_3")
mycursor.execute("use library_3")
mycursor.execute("create table if not exists available_books(id int,
name varchar(50), subject varchar(50), quantity int)")
mycursor.execute("create table if not exists issued(id int, name
varchar(50), subject varchar(50), s_name varchar(50), s_class
varchar(50))")
mycursor.execute("create table if not exists login(user varchar(50),
password varchar(50))")
mydb.commit()
flag=0
mycursor.execute("select * from login")
for i in mycursor: #()
flag=1
if flag==0:
mycursor.execute("insert into login values('user','book')")
mydb.commit()
#################################Loopss///main working

while True:
print("""
1. Login
2. Exit
""")
ch=int(input("Enter your choice:"))
if ch==1:
pas=input("Enter password:")
mycursor.execute("select * from login")
for i in mycursor:
t_user,t_pas=i
if pas==t_pas:
print("Login Successfully...")
loop1='n'
while loop1=='n':
print("""
____________________________________
1. Add New Books
2. Remove Any Book
3. Issue Book To Student
4. Deposit Book
5. View Available Books
6. View Issued Books
7. Logout
____________________________________
""")
ch=int(input("Enter your choice: "))
if ch==1:
loop2='y'
while loop2=='y':
print("All Information are Mandatory to be filled!!")
idd=int(input("Enter Book id: "))
name=input("Enter Book Name: ")
subject=input("Enter Subject: ")
quan=int(input("Enter quantity: "))
mycursor.execute("insert into available_books
values('"+str(idd)+"','"+name+"','"+subject+"','"+str(quan)+"')")
mydb.commit()
print("Book Added Successfully...")
loop2=input("Do You Want To Add Another
Book?(y/n)").lower()
loop1=input("Do You Want To Logout?(y/n)").lower()
elif ch==2:
idd=int(input("Enter Id To Remove Book: "))
mycursor.execute("select * from available_books")
flag=0
for i in mycursor:
t_id,t_name,t_subject,t_quan=i
if t_id==idd:
flag=1
if flag==1:
mycursor.execute("Delete From available_books where
id='"+str(idd)+"'")
mydb.commit()
print("Book Removed Successfully...")
else:
print("Book id is Wrong...")
elif ch==3:
loop2='y'
while loop2=='y':

idd=int(input("Enter Book ID: "))


s_name=input("Enter Student Name: ")
s_class=input("Enter Student Class: ")
mycursor.execute("select * from available_books where
id='"+str(idd)+"'")

flag=0
for i in mycursor:
t_id,t_name,t_subject,t_quan=i
flag=1
quan=t_quan-1
if flag==1:
if t_quan>=0:
mycursor.execute("insert into issued
values('"+str(idd)+"','"+t_name+"','"+t_subject+"','"+s_name+"','"+s_cla
ss+"')")
mycursor.execute("update available_books set
quantity='"+str(quan)+"'")
mydb.commit()
print("Book Issued Successfully...")
loop2=input("Do You Want to Issue More
Books...?(y/n)").lower()

else:
print("Book Not Available...")
else:
print("Invalid Input...")
loop1=input("Do You Want to Logout?(y/n)").lower()

elif ch==4:
loop2='y'
while loop2=='y':
idd=int(input("Enter Book Id: "))
s_name=input("Enter Student Name: ")
s_class=input("Enter Student Class: ")
mycursor.execute("select * from issued")
flag=0
for i in mycursor:
t_id,t_name,t_subject,t_s_name,t_s_class=i
if t_id==idd and t_s_name==s_name and
t_s_class==s_class:
flag=1
if flag==1:
mycursor.execute("select * from available_books
where id='"+str(idd)+"'")
for i in mycursor:
t_id,t_name,t_subject,t_quan=i
quan=t_quan+1
mycursor.execute("delete from issued where
id='"+str(idd)+"' and s_name='"+s_name+"'and s_class='"+s_class+"'")
mycursor.execute("update available_books set
quantity='"+str(quan)+"'")
mydb.commit()
print("Book Deposited Successfully...")
loop2=input("Do You Want To Deposit More
books?(y/n)").lower()
else:
print("Not Issued Yet...")
loop1=input("Do You Want To Logout?(y/n)").lower()
elif ch==5:
mycursor.execute("select * from available_books")
print("ID | NAME | SUBJECT | QUANTITY")
for i in mycursor:
a,b,c,d=i
print(f"{a}|{b}|{c}|{d}")
elif ch==6:
mycursor.execute("select * from issued")
print("ID | NAME | SUBJECT | S_NAME |S_CLASS")
for i in mycursor:
a2,b2,c2,d2,e2=i
print(f"{a2}|{b2}|{c2}|{d2}|{e2}")
elif ch==7:
break

else:
print("Wrong Passwaord...")

elif ch==2:
break

You might also like