Reputation: 55
In Node.js what is correct syntax for select with two where parameters.
var mysql = require("mysql");
connection.connect();
connection.query('SELECT * FROM id WHERE email=? AND password=?', [e] , [p],
function(err, rows){
if (err){
throw err;
}else{
for (var i in rows) {
console.log('name: ', rows[i].name);
open("http://localhost:9383/tweets");
}
}
});
Upvotes: 1
Views: 100
Reputation: 25862
you want to include multiple parameters inside the bracket separated by a comma
connection.query('SELECT * FROM id WHERE email=? AND password=?', [e, p], function(err, rows){...});
see DOCUMENTATION
search for Alternatively, you can use ??
on the page, and the code block will be right below there for an example.
BONUS:
two question marks means its an identifier so you can specify table names like that if you would like.
connection.query('SELECT * FROM ?? WHERE email=? AND password=?', ['id', e, p], function(err, rows){...});
Upvotes: 2