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")
- hapus=input("Hapus data? (y/t) ").lower()
- if(hapus=="y"):
- sql = "DELETE FROM tblmahasiswa WHERE npm_mhs=%s"
- val = (npm,)
- cursor.execute(sql, val)
- db.commit()
- print("{} data berhasil dihapus".format(cursor.rowcount))
- ulang=input("\nUlangi hapus data? (y/t) ").lower()
- if(ulang!="y"):
- break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement