jeudi 12 avril 2018

Python IF statements with common ELSE

I have this code which is used for validating multiple entry boxes, however my problem is that with the current code if the first IF statement is true then the rest of the IF statements will not be sought through. This means that if there is an error in the first entry box the rest of the entry boxes do not get validated, this is my code:

            if (len(MemberID)) > 4:
                  self.MemberIDError.configure(fg = "red") 
            elif (len(Postcode)) > 7:
                  self.PostcodeError.configure(fg = "red")                      
            elif (len(Age)) > 3:
                  self.AgeError.configure(fg = "red")
            elif (len(Mass)) > 3:
                  self.MassError.configure(fg = "red")                        
            elif (Name == '') or (MemberID == '') or (Postcode == '') or (Age == '') or (Gender == '') or (Mass == ''):
                self.CreateError.configure(fg = "red")
                conn.commit()
            else:
                List = [Name, MemberID, Postcode, Age, Gender, Mass]
                cursor.execute("INSERT INTO memb(Name, MemberID, Postcode, Age, Gender, Mass) VALUES (?,?,?,?,?,?)",(Name, MemberID, Postcode, Age, Gender, Mass))
                conn.commit()

Aucun commentaire:

Enregistrer un commentaire