Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

my function to update records in python tkinter with mysql does not work correctly

I made an interface where they fill out a series of forms and are saved in the database, I made a button to update the data in case the user has made a mistake and he can update it but when updating what it does is that it updates to all registered users and not just the one I am selecting, it must be an error in the query but I am new to this

the idea is to update a single data from the interface

id_postulante is a auto-incrementing field and it is not a variable like the rest of the fields

def actualizar(self):
       if self.nombre_var.get()=="" or self.apellido_var.get()=="" or self.cedula_var.get()=="" or self.fdn_var.get()=="" or self.genero_var.get()=="" or self.telefono_var.get()=="" or self.correo_var.get()=="" or self.cargo_aspira_var.get()=="" or self.estado_civil_var.get()=="":
           messagebox.showerror("Error","Seleccion el registro que desea actualizar!!!")
       else:
           con=pymysql.connect(host="localhost", user="root",password="", database="postulantebd")
           cur = con.cursor()
           cur.execute("update postulantes set nombre=%s, apellido=%s, cedula=%s, fdn=%s, genero=%s, telefono=%s, correo=%s, estadoCivil=%s, cargoAspira=%s, direccion=%s,imagen=%s, descripcion=%s,indicador=%s where id_postulante",(
               self.nombre_var.get(),
               self.apellido_var.get(),
               self.cedula_var.get(),
               self.fdn_var.get(),
               self.genero_var.get(),
               self.telefono_var.get(),
               self.correo_var.get(),
               self.estado_civil_var.get(),
               self.cargo_aspira_var.get(),
               self.txt_direccion.get('1.0', 'end-1c'),
               self.blobImagen,
               self.descripcion_var.get('1.0', 'end-1c'),
               self.indicador_var.get('1.0', 'end-1c')
               ))
           con.commit()
           self.foto.grid_remove()
           self.fetch_all()
           self.limpiar()
           con.close()
           messagebox.showinfo("Exelente","Se actualizó correctamente el registro")
question from:https://stackoverflow.com/questions/65641824/my-function-to-update-records-in-python-tkinter-with-mysql-does-not-work-correct

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...