100% found this document useful (2 votes)
1K views

Slam Book Python Programming

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)
1K views

Slam Book Python Programming

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

Menu.

py

def MenuBook():

while True:

SBook.clrscreen()

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:

SBook.insertData()

elif choice==2:

SBook.display()

elif choice==3:

SBook.Searchfrnd()

elif choice==4:

SBook.deletedata()

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:

SBook.clrscreen()

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

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

Menu.MenuBook()

print("====================================================")
SBOOK.py

import mysql.connector

from mysql.connector import errorcode

from datetime import date, datetime, timedelta

from mysql.connector import (connection)

import os

import platform

def clrscreen():

if platform.system()=="Windows":

print(os.system("cls"))

def display():

try:

os.system('cls')

cnx = connection.MySQLConnection(user='root', password='mysql', host='localhost',

database='slambook')

Cursor = cnx.cursor()

query = ("SELECT * FROM friends")

Cursor.execute(query)

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

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

print("id : ",id)

print("Name : ",name)

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

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

Cursor.close()

cnx.close()

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

except mysql.connector.Error as err:

if err.errno == errorcode.ER_ACCESS_DENIED_ERROR: print("Something is wrong


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

else:

print(err)

else:

cnx.close()

def insertData():

try:

cnx = connection.MySQLConnection(user='root',

password='mysql',

host='127.0.0.1',

database=‘slambook’)

Cursor = cnx.cursor()

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)

Cursor.execute(Qry,data)

Make sure data is committed to the database cnx.commit()

Cursor.close()

cnx.close()

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

except mysql.connector.Error as err:

if err.errno == errorcode.ER_ACCESS_DENIED_ERROR:

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

elif err.errno == errorcode.ER_BAD_DB_ERROR:

print("Database does not exist")

else:

print(err)

cnx.close()

def deletedata():

try:

cnx = connection.MySQLConnection(user='root',

password='mysql',

host='127.0.0.1',

database=‘slambook’)

Cursor = cnx.cursor()
id=input("Enter id of friend to be deleted : ")

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

del_rec=(id,)

Cursor.execute(Qry,del_rec)

Make sure data is committed to the database cnx.commit()

Cursor.close()

cnx.close()

print(Cursor.rowcount,"Record(s) Deleted Successfully.............")

except mysql.connector.Error as err:

if err.errno == errorcode.ER_ACCESS_DENIED_ERROR:

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

elif err.errno == errorcode.ER_BAD_DB_ERROR:

print("Database does not exist")

else:

print(err)

cnx.close()

def Searchfrnd():

try:

cnx = connection.MySQLConnection(user='root',

password='mysql',

host='127.0.0.1',

database=‘slambook’)
Cursor = cnx.cursor()

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

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

rec_srch=(id,)

Cursor.execute(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 cnx.commit()

Cursor.close()

cnx.close()

except mysql.connector.Error as err:


if err.errno == errorcode.ER_ACCESS_DENIED_ERROR:

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

elif err.errno == errorcode.ER_BAD_DB_ERROR:

print("Database does not exist")

else:

print(err)

cnx.close()

def Updatefrnd():

try:
cnx = connection.MySQLConnection(user='root',

password='mysql',

host='127.0.0.1',

database=‘slambook’)

Cursor = cnx.cursor()

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)

Cursor.execute(Qry,data)

Make sure data is committed to the database''' cnx.commit()

Cursor.close()

cnx.close()

print(Cursor.rowcount,"Record(s) Updated Successfully.............")

except mysql.connector.Error as err:


if err.errno == errorcode.ER_ACCESS_DENIED_ERROR:

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

elif err.errno == errorcode.ER_BAD_DB_ERROR:

print("Database does not exist")

else:

print(err)

cnx.close()

Updatefrnd()

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy