AshleeCW
AshleeCW

Reputation: 29

Syntax error in flask MySQL LIKE concat query

I'm using MySQL with Python Flask and trying to do a search query with LIKE concat however I am getting a Syntax error with it or a Type Error if I use different marks around my symbols.

name_search = form.name.data
cursor.execute('SELECT id, name, surname FROM users WHERE surname LIKE CONCAT ('%', '%s', '%')', [name_search])

Upvotes: 0

Views: 143

Answers (1)

Jason Groulx
Jason Groulx

Reputation: 410

You could add the percentage signs within the variable

cursor.execute("SELECT id, name, surname FROM users 
    WHERE surname LIKE '{}'".format("%" + name_search + "%"))

Upvotes: 1

Related Questions