100% found this document useful (2 votes)
812 views11 pages

Slam Book Management in Python

The document contains Python code for a menu-driven program to manage a slam book (address book) database. The menu allows the user to: 1) Add new records, 2) Display all records, 3) Search for a record, 4) Delete a record, and 5) Update an existing record. It imports and calls functions defined in other files to perform database operations like inserting, retrieving, updating, and deleting records in a MySQL database table using SQL queries.

Uploaded by

Muthu Manickam
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
100% found this document useful (2 votes)
812 views11 pages

Slam Book Management in Python

The document contains Python code for a menu-driven program to manage a slam book (address book) database. The menu allows the user to: 1) Add new records, 2) Display all records, 3) Search for a record, 4) Delete a record, and 5) Update an existing record. It imports and calls functions defined in other files to perform database operations like inserting, retrieving, updating, and deleting records in a MySQL database table using SQL queries.

Uploaded by

Muthu Manickam
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
  • MenuBook.py Script
  • Slam_Book.py Script
  • SBOOK.py Script

Menu.

py

def MenuBook():

while True:

[Link]()

print("\t\t\t SlamBook\n")

print("=====================================================")

print("1. Add Record ")

print("2. Display Records ")

print("3. Search Record ")

print("4. Delete Record ")

print("5. Update Record ")

print("6. Return to Main Menu ")

print("=====================================================")

choice=int(input("Enter Choice between 1 to 5-------> : "))

if choice==1:

[Link]()

elif choice==2:

[Link]()

elif choice==3:

[Link]()

elif choice==4:

[Link]()

elif choice==5:

print("No such Function")

elif choice==6:
return

else:

print("Wrong Choice......Enter Your Choice again")

x=input("Enter any key to continue")

#----------------------------------------------------------------------------------------
Slam_Book .py

import Menu

import SBook

while True:

[Link]()

print("\t\t\t Slam Book Management\n")

print("=====================================================")

[Link]()

print("====================================================")
[Link]

import [Link]

from [Link] import errorcode

from datetime import date, datetime, timedelta

from [Link] import (connection)

import os

import platform

def clrscreen():

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

print([Link]("cls"))

def display():

try:

[Link]('cls')

cnx = [Link](user='root', password='mysql', host='localhost',

database='slambook')

Cursor = [Link]()

query = ("SELECT * FROM friends")

[Link](query)

for (id,name,addess,phno) in Cursor:

print("--------------------------------------------------------------------")

print("id : ",id)

print("Name : ",name)

print("address : ",address)
print("phno : ",phno)

print("------------------------------------------------------------")

[Link]()

[Link]()

print("completed !!!!!!")

except [Link] as err:

if [Link] == errorcode.ER_ACCESS_DENIED_ERROR: print("Something is wrong


with your user name or password") elif [Link] ==
errorcode.ER_BAD_DB_ERROR: print("Database does not exist")

else:

print(err)

else:

[Link]()

def insertData():

try:

cnx = [Link](user='root',

password='mysql',

host='[Link]',

database=‘slambook’)

Cursor = [Link]()

id=input("Enter id : ")

name=input("Enter Name : ")

add=input("Enter address : ")

ph=int(input("Enter phno : "))


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

data = (id,name,add,ph)

[Link](Qry,data)

Make sure data is committed to the database [Link]()

[Link]()

[Link]()

print("data saved successfully............")

except [Link] as err:

if [Link] == errorcode.ER_ACCESS_DENIED_ERROR:

print("Something is wrong with your user name or password")

elif [Link] == errorcode.ER_BAD_DB_ERROR:

print("Database does not exist")

else:

print(err)

[Link]()

def deletedata():

try:

cnx = [Link](user='root',

password='mysql',

host='[Link]',

database=‘slambook’)

Cursor = [Link]()
id=input("Enter id of friend to be deleted : ")

Qry =("""DELETE FROM Friends WHERE id = %s""")

del_rec=(id,)

[Link](Qry,del_rec)

Make sure data is committed to the database [Link]()

[Link]()

[Link]()

print([Link],"Record(s) Deleted Successfully.............")

except [Link] as err:

if [Link] == errorcode.ER_ACCESS_DENIED_ERROR:

print("Something is wrong with your user name or password")

elif [Link] == errorcode.ER_BAD_DB_ERROR:

print("Database does not exist")

else:

print(err)

[Link]()

def Searchfrnd():

try:

cnx = [Link](user='root',

password='mysql',

host='[Link]',

database=‘slambook’)
Cursor = [Link]()

id=input("Enter id be Searched from the friends : ")

query = ("SELECT * FROM Friends where id = %s ")

rec_srch=(id,)

[Link](query,rec_srch)

Rec_count=0

for (Bno,Bname,Author,price,publ,qty,d_o_purchase) in Cursor:

Rec_count+=1

for (id,name,addess,phno) in Cursor:

print("--------------------------------------------------------------------")

print("id : ",id)

print("Name : ",name)

print("address : ",address)
print("phno : ",phno)

print("------------------------------------------------------------")

if Rec_count%2==0:

input("Press any key to continue")

clrscreen()

print(Rec_count, "Record(s) found")

Make sure data is committed to the database [Link]()

[Link]()

[Link]()

except [Link] as err:


if [Link] == errorcode.ER_ACCESS_DENIED_ERROR:

print("Something is wrong with your user name or password")

elif [Link] == errorcode.ER_BAD_DB_ERROR:

print("Database does not exist")

else:

print(err)

[Link]()

def Updatefrnd():

try:
cnx = [Link](user='root',

password='mysql',

host='[Link]',

database=‘slambook’)

Cursor = [Link]()

id=input("Enter id of frined to be Updated : ")

query = ("SELECT * FROM Friends where id = %s ")

rec_srch=(id,)

print("Enter new data ")

name=input("Enter new Name : ")

add=input("Enter address : ")

ph=input("Enter phno: ")

Qry = ("UPDATE Friends SET name=%s,address=%s,"\ "phno=%s "\

"WHERE id=%s")

data = (name,add,ph, bno)

[Link](Qry,data)

Make sure data is committed to the database''' [Link]()

[Link]()

[Link]()

print([Link],"Record(s) Updated Successfully.............")

except [Link] as err:


if [Link] == errorcode.ER_ACCESS_DENIED_ERROR:

print("Something is wrong with your user name or password")

elif [Link] == errorcode.ER_BAD_DB_ERROR:

print("Database does not exist")

else:

print(err)

[Link]()

Updatefrnd()

Menu.py 
 
def MenuBook(): 
 
while True: 
 
SBook.clrscreen() 
 
print("			 SlamBook
") 
 
print("======================
return 
 
else: 
 
print("Wrong Choice......Enter Your Choice again") 
 
x=input("Enter any key to continue") 
 
#-----------
Slam_Book .py 
 
import Menu 
 
import SBook 
 
while True: 
 
SBook.clrscreen() 
 
print("			 Slam Book Management
")
SBOOK.py 
 
 
import mysql.connector 
 
from mysql.connector import errorcode 
 
from datetime import date, datetime, timed
print("phno 
: ",phno) 
 
 
print("------------------------------------------------------------") 
 
Cursor.close() 
 
 
cnx.
"VALUES (%s, %s, %s, %s, %s, %s, %s)") 
 
 
data = (id,name,add,ph) 
 
Cursor.execute(Qry,data) 
 
Make sure data is comm
id=input("Enter id of friend  to be deleted : ") 
 
Qry =("""DELETE FROM Friends WHERE id = %s""") 
 
del_rec=(id,) 
 
Curs
Cursor = cnx.cursor() 
 
 
id=input("Enter id be Searched from the friends : ") 
 
query = ("SELECT * FROM Friends where id
if err.errno == errorcode.ER_ACCESS_DENIED_ERROR: 
 
print("Something is wrong with your user name or password") 
 
elif err.
cnx = connection.MySQLConnection(user='root', 
 
password='mysql', 
 
host='127.0.0.1', 
 
database=‘slambook’) 
 
Cursor = c

You might also like