( Record 16 ) Python mysql interface updation[1]
( Record 16 ) Python mysql interface updation[1]
#Record Program 16
#Source Code
import mysql.connector
mydb = mysql.connector.connect(host ='localhost',user ='root',password='admin',database='cvt11')
mycursor = mydb.cursor()
print("student record updation")
rno = int(input("Enter rno to update the record:"))
query = "select*from student where Roll_no={}".format(rno)
mycursor.execute(query)
myrec = mycursor.fetchone()
if myrec != None:
print('## Record Found - Details are: ##')
print(myrec)
ch = input('Do you want to update marks (y/n):')
if ch == 'y':
marks = float(input('Enter new updated marks:'))
query ='UPDATE student set marks ={} where Roll_no ={}'.format(marks,rno)
mycursor.execute(query)
mydb.commit()
print("## Record(s) updated ##")
else:
print('Sorry ! No such student exists')
mydb.close()
#yohan - 12136
#Record Program 16
#Output
student record updation
Enter rno to update the record:12003
## Record Found - Details are: ##
(12003, 'DIVYA', 70.5, 'C')
Do you want to update marks (y/n):y
Enter new updated marks:72.1
## Record(s) updated ##