Skip to content
Advertisement

SQL wildcards in PYMYSQL search

I am struggling to put together a simple SQL wildcard search for my Flask application.

I am using an HTML form field to run a simple mysql query “WHERE CustomerName LIKE ‘a%'”- https://www.w3schools.com/sql/sql_wildcards.asp – However I am unable to get the right positioning for the search place holder…

here the HTML form field (working fine)

The python route

and finally the database helper function

The error seems to be around the structure of the LIKE ‘%s’, since the query works fine when using an ‘=’ statement.

Thank you in advance for any help.

Advertisement

Answer

After quite some trying I fount the solution to this problem: the ‘%’ wildcard operators need to be placed as follows:

the rest of the code is correct

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement