0% found this document useful (0 votes)
129 views

Menu Driven Program Studentrecords

This Python code defines functions to add, update, delete, and display student records stored in a MySQL database. It uses MySQL connector to connect to a local database called 'school' and allows a user to select an option to perform CRUD operations by calling the corresponding function and prompting for required inputs.

Uploaded by

Eshaan Kuttikad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
129 views

Menu Driven Program Studentrecords

This Python code defines functions to add, update, delete, and display student records stored in a MySQL database. It uses MySQL connector to connect to a local database called 'school' and allows a user to select an option to perform CRUD operations by calling the corresponding function and prompting for required inputs.

Uploaded by

Eshaan Kuttikad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

import mysql.

connector as sql

def addrecord():
db = sql.connect(host='localhost',user = 'root', passwd = 'P@5sw0rd', database
= 'school')
cursor = db.cursor()
rollno = int(input('Enter rollno of student: '))
name = input('Enter name of student: ')
marks = int(input('Enter student marks: '))
grade = input("Enter student grade: ")
cursor.execute(f"insert into studentdata(ROLLNO,NAME,MARKS,GRADE)
values({rollno},'{name}',{marks},'{grade}')")
db.commit()
cursor.close()
db.close()

def updaterecord():
column = input('Enter column to be updated: ')
value = input('Enter new value: ')
rollno = input("Enter rollno to be updated: ")
db = sql.connect(host='localhost', user='root', passwd='P@5sw0rd',
database='school')
cursor = db.cursor()
try:
cursor.execute(f"UPDATE studentdata set {column} = {value} where ROLLNO =
{rollno}")
except:
cursor.execute(f"Update studentdata set {column} = '{value}' where ROLLNO =
{rollno}")
db.commit()
cursor.close()
db.close()

def deleterecord():
rollno = int(input("Enter rollno of student to be deleted"))
db = sql.connect(host='localhost', user='root', passwd='P@5sw0rd',
database='school')
cursor = db.cursor()
cursor.execute(f"delete from Studentdata where ROLLNO = {rollno}")
db.commit()
cursor.close()
db.close()

def displayrecord():
db = sql.connect(host='localhost', user='root', passwd='P@5sw0rd',
database='school')
cursor = db.cursor()
cursor.execute("Select * from Studentdata")
data = cursor.fetchall()
for i in data:
print(i)

while True:
print('''1 - add record
2 - update record
3 - delete record
4 - display record
5 - exit''')
ui = int(input('Enter option number: '))
if ui ==1:
addrecord()
elif ui ==2:
updaterecord()
elif ui ==3:
deleterecord()
elif ui ==4:
displayrecord()
elif ui == 5:
break
else:
print('Enter proper option number')

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