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.

anni
  • 338
  • 2
  • 12

1 Answers1

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.

Mustafa
  • 10,013
  • 10
  • 70
  • 116
  • works like a charm. Didn't see this in the documentation though. I thought one ? will be replaced with one array. Thanks :) – anni Jan 22 '13 at 13:00