DEV Community

Hussein Ouda
Hussein Ouda

Posted on

Python search function not working in the program

I wrote a function to search the program:

def search(self):
        con = pymysql.connect(host='localhost', user = 'root', password = '', database = 'employ')
        cur = con.cursor()
        cur.execute("select * from employees where " +
        str(self.se_by.get())+" LIKE '%"+ str(self.se_var.get())+"%'")
        rows = cur.fetchall()
        if len (rows) !=0:
            self.student_table.delete(*self.student_table.get_children())
            for row in rows:
                self.student_table.insert("", END, value=row)
            con.commit()
        con.close()
Enter fullscreen mode Exit fullscreen mode

And do not work! It gives the following error:

pymysql.err.ProgrammingError: (1064, "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 'LIKE '%%'' at line 1")
Enter fullscreen mode Exit fullscreen mode

please help

Discussion (0)