0% found this document useful (0 votes)
18 views2 pages

12 Cs Project Demo

The document outlines a Python script for a Student Management System that connects to a MySQL database. It includes functions to insert, update, search, and delete student records, with user prompts for input. The script runs in a loop allowing users to choose different operations until they decide to exit.
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)
18 views2 pages

12 Cs Project Demo

The document outlines a Python script for a Student Management System that connects to a MySQL database. It includes functions to insert, update, search, and delete student records, with user prompts for input. The script runs in a loop allowing users to choose different operations until they decide to exit.
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

# project sample

# Student Management System


# Create data base
# create tables
import mysql.connector as mysq

def insert_records():

con=mysq.connect(host="localhost",database="phythonsql",user="root",password="",cha
rset="utf8")
if con.is_connected():
cur=con.cursor()
rollno=input("enter rollno")
sname=input("enter student name")
sqlcommand="insert into student values({},'{}');".format(rollno,sname)
cur.execute(sqlcommand)
con.commit()
print("data inserted successfully..!!")
con.close()

def update_records():
rn=int(input("enter rollno "))
print("1. to update Name")
print("2. to update address")
print("3. to update Phno")
x=int(input("enter your choice"))
if x==1:
sname=input("enter new name")
sqlcommand="update student set sname={} where rollno={}".format(sname,rn)
elif x==2:
sname=input("enter new name")
sqlcommand="update student set sname={} where rollno={}".format(sname,rn)
elif x==3:
sname=input("enter new name")
sqlcommand="update student set sname={} where rollno={}".format(sname,rn)

con=mysq.connect(host="localhost",database="phythonsql",user="root",password="",cha
rset="utf8")
if con.is_connected():
cur=con.cursor()
cur.execute(sqlcommand)
con.commit()
print("data inserted successfully..!!")
con.close()

def search_records():
pass

def delete_records():
pass

while True:

print("1. insert record")


print("2.update records ")
print("3.search student details")
print("4. delete records")
print("5. exit")
choice=int(input("enter your choice "))
if choice==1:
insert_records()
elif choice==2:
update_records()
elif choice==3:
search_records()
elif choice==4:
delete_records()
else:
break

You might also like