Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import mysql.connector
- db = mysql.connector.connect(host="localhost",
- user="root",
- password="", database="db112300xx")
- cursor = db.cursor()
- while(True):
- npm=input("Input NPM: ")
- val=(npm,)
- sql = "SELECT * FROM tblmahasiswa WHERE npm_mhs=%s"
- cursor.execute(sql,val)
- results = cursor.fetchall()
- if(cursor.rowcount==0):
- print("Record tidak ada/ditemukan ...")
- else:
- for data in results:
- print (f"Nomor Record : {data[0]}\n"
- f"NPM Mahasiswa : {data[1]}\n"
- f"Nama Mahasiswa : {data[2]}\n"
- f"Jenis Kelamin (P/L) : {data[3]}\n"
- f"Program Studi (SI/IF): {data[4]}\n")
- ubah=input("Ubah data? (y/t) ").lower()
- if(ubah=="y"):
- nama = input("Na ma Mahasiswa : ").title()
- jk = input("Jenis Kelamin (P/L) : "). upper()
- prodi= input("Program Studi (SI/IF): ").upper()
- val = (nama,jk,prodi,npm)
- sql = "UPDATE tblmahasiswa SET nm_mhs=%s, jk_mhs=%s, prodi=%s WHERE npm_mhs=%s"
- cursor.execute(sql, val)
- db.commit()
- print("{} data berhasil diubah".format(cursor.rowcount))
- ulang=input("\nUlangi ubah data? (y/t) ").lower()
- if(ulang!="y"):
- break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement