Skip to content
Advertisement

Unable to execute a query on flask using MqSQL

Hello there im trying to execute a SQL query using Flask with mysqldatabase, the query returns as a JSON managed my JQuery on the front end. The goal is to use a search bar to find any matches with the data base. The query works just fine if I use just one “like” sentence, for example.

JavaScript

But in the moment I use and “OR” sentence for multiple search like this:

JavaScript

The query does not work at all and outputs this error

error for jQuery

Curious enough executing the same query on Dbebaber works just fine, obviously replacing ‘{}%’ whit ‘string%’, I have no idea why the query refuses to work, in addition I’m including the full python and Jquery code.

Flask:

JavaScript

HTML and JQUERY

JavaScript

Any help or advice is welcome.

Advertisement

Answer

Please read up on SQL injection vulnerabilities, and use:

JavaScript

Which will escape user input, so malicious users cannot write SQL commands into the searchbox.

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