0

I'm using node.js to write an HTTP server for interacting with clients and storing the data sent by them into a mysql database. I'm using node-mysql module to interact with database. Following is a snippet from my code:

mysql_conn.query('INSERT INTO systems VALUES ( ? )', [system.ClientID,
    system.Application, system['System Information']], function(err, result) {
    if (err) {
        cb(err, res);
    } else {
        resData = {Status : 'Success'};
        cb(null, res, resData);
    }
});

The resulting query looks like this:

INSERT INTO systems VALUES ( 'ED1758FD-1ED7-4907-A4FF-BCA41830124A' )

I'm passing an array with three elements but only one show up in the query. The documentation says:

Arrays are turned into list, e.g. ['a', 'b'] turns into 'a', 'b'

Am I doing something wrong? I'm very new to javascript. Please tolerate the ignorance if any.

1 Answer 1

1

If you have 3 variables, there should be 3 ? In other words your SQL query should look like this: INSERT INTO systems VALUES ( ?, ?,? ) If you are not sure about the order, and you want to specifiy an order you should change your query to something like this: INSERT INTO systems(field1, field2, field3) VALUES ( ?, ?,? ) where fields are actual fields in your table in MySQL.

Sign up to request clarification or add additional context in comments.

1 Comment

works like a charm. Didn't see this in the documentation though. I thought one ? will be replaced with one array. Thanks :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.