Helo ,

I am working actualy on a function that delete a row from a table in a database , it works good with this python code :

def supprimer():
            global rows
            global element
            global listelement
            idsupprvar = idsuppr_entry.get()
            db = MySQLdb.connect(host = "localhost", user = "user", passwd = "123456",db = "users",charset = "utf8" , use_unicode=True) 
            curs = db.cursor()
            #curs.execute('SELECT idpersonne FROM parcinfo;')
            #rows = curs.fetchall()
            #if rows :                
               # for z in rows:
                 #   if idsupprvar == z[0] :
            print idsupprvar
            curs.execute("DELETE FROM users.parcinfo WHERE idpersonne = %s"%(idsupprvar))
            curs.close()
            db.commit()
            lab1.config(text="l'enregistrement dont l'id = '%s' a été bien supprimé de la base de données"%(idsupprvar))
            idsuppr_entry.delete(0,END)
            labsupprimer.config(text="Pour supprimer un autre enregistrement , saisir son id puis cliquer sur supprimer")

my question is how to check if the "idpersonne" exist before deleting it row .

Hello again , the problem was , that the elements of the colomne "idpersonne" are long integers , and that add an "L" after elements , now after having a list of elements of the the colomne "idpersonne" how can i check if the received value exist in the list , i tried :

if idsupprvar in tmp :
               curs.execute("DELETE FROM Users.parcinfo WHERE idpersonne = %s"%(idsupprvar))
               curs.close()
               db.commit()
               lab1.config(text="l'enregistrement dont l'id = '%s' a été bien supprimé de la base de données"%(idsupprvar))
               idsuppr_entry.delete(0,END)
               labsupprimer.config(text="Pour supprimer un autre enregistrement , saisir son id puis cliquer sur supprimer")
            else :
               lab1.config(text="l'enregistrement dont l'id = '%s' n'existe pas  dans la base de données"%(idsupprvar))

tmp is the list of elements of the colomne "idpersonne" , that go directly to execute the "else" function !

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.