Home > Software design >  SQLITE record not updating
SQLITE record not updating

Time:09-22

Ok so this is my code to create the database , create a skelenton user (create_user) , update f_name field (save_fName)

c.execute("""CREATE TABLE UserData (
        id int AUTO_INCREMENT,
        user_id int,
        f_name text,
        phone_no text,
        f_code int,
        Recording_url text,
        rrt_number int,
        c_cex int,
        c_y int,
        nt_number int,
       x_pin int
    )""")

def save_fName(sf_N, userid):
   c.execute(f"UPDATE UserData SET f_name = ''' {sf_N} ''' WHERE user_id = ''' {userid} '''")
   conn.commit()

def create_user(userid):
   sql = f"Insert into UserData values(0,{userid},'Notavailable','Notavailable',0,'Notavailable',0,0,0,0,0)"
   c.execute(sql)
   conn.commit()

I have tried updating into phone_no field using exactly the same code as save_fName function only with different parameters and that works just fine but when i try to update a record at the f_name field using save_fName it doesn't just update, no errors but it stays at 'Notavailable'

CodePudding user response:

your request is badly formed and not secure. use tuples and question marks

def save_fName(sf_N, userid):
   c.execute("UPDATE UserData SET f_name = ? WHERE user_id = ?", (sf_N, userid))
   conn.commit()
  • Related