Home > OS >  i got error while rename the data in python and sqlite3
i got error while rename the data in python and sqlite3

Time:01-20

So i had a problem, i make CRUD program with python with sqlite3. im already add data to db and want to rename the data, and then im runnin the code and there appear error problem in my definition. heres the error.

line 45, in rename_data
    c.execute(f"UPDATE data SET nama={nama_baru} WHERE nama={nama_lama}")
sqlite3.OperationalError: no such column: Bintang
                                                 

heres the code

cur.execute("""CREATE TABLE IF NOT EXISTS data (nim integer not null, nama text, prodi text)""")

    c = con.cursor()
    print('''
    1.NIM
    2.Nama
    3.Jurusan
    ''')
    user_input = int(input('Masukan Opsi: '))
    if user_input == 1: 
        nim_lama = int(input('Masukan NIM lama = '))
        nim_baru = int(input('Masukan NIM baru = '))
        c.execute(f"UPDATE data SET nim={nim_baru} WHERE nim={nim_lama}")
        print(f'NIM sudah di ubah menjadi {nim_baru}')
    elif user_input == 2: 
        nama_lama = str(input('Masukan Nama lama = '))
        nama_baru = str(input('Masukan Nama baru = '))
        c.execute(f"UPDATE data SET nama={nama_baru} WHERE nama={nama_lama}")
        print(f'Nama sudah di ubah menjadi {nama_baru}')
    elif user_input == 3: 
        prodi_lama = str(input('Masukan Jurusan lama = '))
        prodi_baru = str(input('Masukan Jurusan baru = '))
        c.execute(f"UPDATE data SET prodi={prodi_baru} WHERE prodi={prodi_lama}")
        print(f'Mata Kuliah sudah di ubah menjadi {prodi_baru}')
    con.commit()

CodePudding user response:

Bruh i just so stupid, i forgot add quotation mark in my parameter.

        print(f"Nama sudah di ubah menjadi '{nama_baru}'")```
  • Related