0% found this document useful (0 votes)
2 views15 pages

SOURCE CODE

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)
2 views15 pages

SOURCE CODE

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

SOURCE

CODE
import mysql.connector

mydb=mysql.connector.connect (host="local

host",user="AADARSH",password="@2024-25")

#CREATING DATABASE AND TABLE

mycursor=mydb.cursor()

mycursor.execute("create a database if not exists store")

mycursor.execute("use store")

mycursor.execute("create table if not exists signup(usename

varchar(20),password varchar(20)")

while True :

print("\n\n===========***************** WELCOME TO

*****************===========""")

print("===========***************** MY BOOK STORE

*****************============""")

print("""\n\n 1:Signup 2:Login""")

ch=int(input("SIGNUP/LOGIN(1,2):"))

#SIGNUP

if ch==1:

username=input("USERNAME:")
password=int(input("PASSWORD:"))

mycursor.execute("insert into signup

values('"+username+"','"+password+"')")

mydb.commit()

print("\nSuccessfully signed up")

#LOGIN

elif ch==2:

username=input("USERNAME: ")

password=int(input("PASSWORD: "))

mycursor.execute("SELECT username FROM signup WHERE username=%s",

(username,))

pot = mycursor.fetchall()

if pot is not None:

print("VALID USERNAME!!!!!")

mycursor.execute("SELECT password FROM signup WHERE password=

%s",(password,))

a= mycursor.fetchall()

if a is not None:
print("""+++++++++++++++++++++++++++++++++LOGIN

SUCCESSFULL++++++++++++++++++++++++++++++++++++++++""")

a=mycursor.fetchall()

mycursor.execute("create table if not exists

Available_books(BookName varchar(30) primary key , Genre varchar(20) ,

Quantity int(3) , Author varchar(20) , Publication varchar(30),Price

int(4)")

mycursor.execute("create table if not exists

Sell_rec(CustomerName varchar(20),PhoneNumber char(10) unique key

BookName varchar(30),Quantity int(100) , Price int(4) Total_Amount

int(200)")

mydb.commit()

a=mycursor.fetchall()

while(True):

print("""\n\n\n\n\n\n\n\n\n1:Add Books \n2:Sell

Books \n3:Search Books \n4:Sell record \n5:Available Books \n6: Total

Income after Latest Reset \n7:Exit""")

a=input(int("\n\nEnter your choice :")

#ADD BOOKS
if a==1:

print("\nAll information prompted are

mandatory to be filled\n")

book=str(input("Enter Book Name:"))

genre=str(input("Genre:"))

quantity=int(input("Enter Quantity:"))

author=str(input("Enter Author

Name :"))

publication=str(input("Enter

Publication House:"))

price=int(input("Enter The Price:"))

mycursor.execute("select * from

Available_Books where bookname='"+book+"'")

row=mycursor.fetchone()

if row is not None:

mycursor.execute("update

Avialable_Books set quantity=quantity+'"+str(quantity)+"' where

bookname ='"+book+"'")

mydb.commit()
print("""++++++++++++++++++++++++++

++++++++SUCCESSFULLY ADDED++++++++++++++++++++++++++++++++++++++++++++

+""")

else:

mycursor.execute("insert into

Available_Book(bookname,genre,quantity,author,publication,price)

values('"+book+"','"+genre+"','"+str(quantity)

+"','"+author+"','"+publication+"','"+str(price)+"'")

mydb.commit()

print("""++++++++++++++++++++++++++

++++++++SUCCESSFULLY ADDED++++++++++++++++++++++++++++++++++++++++++++

+""")

#SELL BOOKS

elif a==2:

print("Available Books.....")

mycursor.execute("select * from

Available_Books")
for x in mycursor:

print(x)

cusname=str(input("Enter customer

name:"))

phno=int(input("Enter Phone Number:"))

book=str(input("Enter Book Name:"))

price=int(input("Enter The Price:"))

n=int(input("Enter quantity:"))

amt=price*n

mycursor.execute("select quantity from

Available_Books where bookname='"+book+"'")

root=mycursor.fetchone()

if max(root)<n:

print(n,"Books are not

available!!!!")

else:

mycursor.execute("select bookname

from Available_Books where bookname='"+book+"'")

log=mycursor.fetchone()
if log is not None:

mycursor.execute("insert into

Sell_rec values('"+cusname+"','"+str(phno)+"','"+book+"','"+str(price)

+"','"+str(n)+"','"+str(amt)+"')")

mycursor.execute("update

Available_Books se quamtity=quantity-'"+str(n)+"' where

bookname='"+book+"'")

mydb.commit()

print("""++++++++++++++++++++++++

++++++++++++++ BOOK HAS BEEN SOLD +++++++++++++++++++++++++++++++++++++

+++++""")

else:

print("BOOK ISNAT

AVAILABLE !!!!!!!")

#SEARCH BOOKS ON THE BASSIS OF GIVEN OPTIONS

elif a==3:

print("""1:Search by name \n2:Search by

genre \n3:Search by author""")

l=int(input("Search by?:"))
#BY BOOKNAME

if l==1:

o=input("Enter Book to search :")

mycursor.execute("select bookname

from Available_Book where bookname='"+o+"'")

tree=mycursor.fetchone()

if tree!=None:

print("""++++++++++++++++++++++++

++++++++++ BOOK IS IN STOCK +++++++++++++++++++++++++++++++++++++++++++

++++++""")

else:

print("BOOK IS NOT IN

STOCK!!!!!!!!!!!!!!!!!")

#BY GENRE

elif l==2:

g=input("Enter genre to search :")

mycursor.execute("select genre from

Available_Book where genre='"+g+"'")


poll=mycursor.fetchone()

if poll is not None:

print("""++++++++++++++++++++++++

++++++++++ BOOK IS IN STOCK +++++++++++++++++++++++++++++++++++++++++++

++++++""")

mycursor.execute("select * from

Available_Book where genre='"+g+"'")

for y in mycursor:

print(y)

else:

print("BOOK IS NOT IN

STOCK!!!!!!!!!!!!!!!!!")

#BY AUTHOR

elif l==3:

au=input("Enter author to search :")

mycursor.execute("select author from

Available_Book where author='"+au+"'")

home=mycursor.fetchone()
if home is not None:

print("""++++++++++++++++++++++++

++++++++++ BOOK IS IN STOCK +++++++++++++++++++++++++++++++++++++++++++

++++++""")

mycursor.execute("select * from

Available_Book where author='"+au+"'")

for z in mycursor:

print(z)

else:

print("BOOK IS NOT IN

STOCK!!!!!!!!!!!!!!!!!")

mydb.commit()

#SELL HISTORY

elif a==4:

print("1:Sellhistory details")

print("2:Reset Sell History")

ty=int(input("Enter your choice:"))


if ty==1:

mycusor.execute("select * from

Sell_Rec")

for u in mycursor:

print(u)

if ty==2:

bb=input("ARE YOU SURE(Y/N):")

if bb=="Y":

mycursor.execute("delete from

Sell_Rec")

mydb.commit()

elif bb=="N":

pass

#AVAILABLE BOOKS

elif a==5:

mycursor.execute("select * from

Available_Books order by bookname")

for v in mycursor:

print(v)

#TOTAL INCOME AFTER LATEST UPDATE


if a==6:

mycursor.execute("UPDATE Sell_Rec SET

TOTAL_Amount = quantity * price")

mycursor.execute("SELECT

SUM(Total_Amount) FROM Sell_Rec")

total_income = mycursor.fetchone()[0]

print(f"Total income after latest update:

(total_income)")

#EXIT

elif a==7:

print("\nThank You")

break

break

#LOGIN ELSE PART

else:

print("""+++++++++++++++++++++++++++++++++

++++ INCORRECT PASSWORD ++++++++++++++++++++++++++++++++++++++++++""")

else:
print("""+++++++++++++++++++++++++++++++++++++++++

INVALID USERNAME +++++++++++++++++++++++++++++++++++++++++++++""")

else:

break
OUTPUT

You might also like