Paul B. Paul B. - 5 months ago 17
MySQL Question

How to SELECT * using multiple variables in MySQL with Node.js and Express?

Hello I am trying to do a request in node.js with MySQL that is similar to

SELECT * FROM table_name WHERE tag="some_word" AND username="some_username"

I have not been able to figure out how to make a request work when wanting to use more than one variable at once. I can get my requests to work when doing something like

SELECT * FROM table_name WHERE username="some_username"

but I can't seem to find any answers on how to do this when adding the AND to the query. Any suggestions? Thank you in advance!


This may be something that you want. Just put whatever variables you want into the filter array and it will insert into the SELECT query.

var some_word;
var some_username;
var queryString = "SELECT * FROM table_name WHERE tag= ? AND username= ?;"
var filter = [some_word, some_username];

connection.query(queryString, filter, function(err, results) {
   //process results

More info at: