node | MySQL multiple WHERE with AND clause

334
July 29, 2017, at 11:31 AM

I am trying to do a statement in node using mysql package. I am trying to select from a table WHERE with a AND clause such as WHERE id = 1 AND course = 1 so far I've got as far as being able to SELECT but I'm getting an error, I can see the error though and it's that there is no AND when I am binding the id.

This is my current code.

let sql = 'SELECT * FROM users WHERE ?';
let values = {
    id: 1,
    course: 1
}
database.query(sql, values, (err, result) => {
}

This is the error I am getting...

SELECT * FROM users WHERE id = 1, course = 1

The query once it has been through node is missing the AND

Any help would be appreciated.

Answer 1

probably should look smth like this:

let sql = 'SELECT * FROM users WHERE id = ? AND course = ?';
database.query(sql, [1, 1], (err, result) => {
}

https://www.w3schools.com/nodejs/shownodejs_cmd.asp?filename=demo_db_where_placeholders

Rent Charter Buses Company
READ ALSO
Node spawn process and store output

Node spawn process and store output

This part of my script is trying to spawn a child that is going to clone a hard driveIt basically works but the issue that I am having is that when I encounter an error and want to store the output, it only stores the first line of the output, excluding...

339
How to put email address in database in React Native

How to put email address in database in React Native

Right now, I have a very basic login form that takes in user inputI'm really new to databases & would like to know how would I start the process of directly putting user inputs into a database upon the user hitting Submit? I've searched Google, SO and surprisingly,...

403
jQuery Bootstrap Date Picker Selected Date Wrong with Fixed Date Value Input

jQuery Bootstrap Date Picker Selected Date Wrong with Fixed Date Value Input

I have jQuery Bootstrap Date PickerIt works normally and OK on input form

347