Skip to content
Advertisement

error 1064 (42000) : You have an error in your SQL syntax near to use %s

I dont know what I done wrong, but the error is : error 1064 (42000) : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘%s’

def forget_password_window(self):
        if self.Mail_address.get()=="":
            messagebox.showerror("Erreur", "Veuillez rentrer une adresse mail valide.", parent=self.app)
        else:
            try:
                mydb = mysql.connector.connect(
                    host = "localhost",
                    user = "username",
                    password = "pwd",
                    auth_plugin='mysql_native_password',
                    database = "mydb"
                )
                cursor = mydb.cursor()
                cursor.execute("""SELECT * FROM Employee WHERE employee_address=%s """,(self.Mail_address.get()))
                row = cursor.fetchone()

I made this code above in my code :

def connexion(self):
        if self.Mail_address.get()=="" or self.Password.get()=="":
            messagebox.showerror("Erreur", "Veuillez saisir l'adresse mail et le mot de passe !", parent=self.app)
        else :
            try:
                mydb = mysql.connector.connect(
                    host = "localhost",
                    user = "username",
                    password = "pwd",
                    auth_plugin='mysql_native_password',
                    database = "mydb"
                )
                cursor = mydb.cursor()
                cursor.execute("""SELECT * from Employee WHERE employee_address=%s and employee_matricule=%s""",(self.Mail_address.get(), self.Password.get()))
                row = cursor.fetchone()

This code is working. So idk why this code is working and the first one is not. NEED HELP ! THX !

Advertisement

Answer

The MySQL connector needs at least a list of 2 dimensions as parameter

So change your code to

def forget_password_window(self):
    if self.Mail_address.get()=="":
        messagebox.showerror("Erreur", "Veuillez rentrer une adresse mail valide.", parent=self.app)
    else:
        try:
            mydb = mysql.connector.connect(
                host = "localhost",
                user = "username",
                password = "pwd",
                auth_plugin='mysql_native_password',
                database = "mydb"
            )
            cursor = mydb.cursor()
            cursor.execute("""SELECT * FROM Employee WHERE employee_address=%s """,(self.Mail_address.get(),))
            row = cursor.fetchone()
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement