I have this for loop that loops through a punch of user inputs and I wanna add them to mysql but I have this error that keeps popping up saying a syntax error in my query I logged the query I send and it fine the callback error query is not the same as the one i sent
here's the loop
for (var j = 0; j <= intLength - 1; j++) {
console.log(intItem[j], "intents looop");
const query1 =
" INSERT INTO intents (intent, version_id,status_intent) VALUES ('" +
intItem[j] +
"', (SELECT MAX (versions.version_id) from versions), '" +
enableStatus +
"')";
console.log(query1, "query11");
s
connection.query(
query1,
params,
function (err, results) {
if (err) {
console.log(
err,
"error from new project in insert to intents"
);
}
}
);
}
and that is the callback error query sql: " INSERT INTO intents (intent, version_id,status_intent) VALUES ('what'test11'', (SELECT MAX (versions.version_id) from versions), 'enable')"
This is the exact error...
code: 'ER_PARSE_ERROR',
errno: 1064,
sqlMessage: "You have an error in your SQL syntax; check the
manual that corresponds to your MySQL server version for the
right syntax to use near 'test103'', (SELECT MAX
(versions.version_id) from versions), 'enable')' at line 1",
sqlState: '42000',
index: 0,
sql: " INSERT INTO intents (intent, version_id,status_intent)
VALUES ('what'test103'', (SELECT MAX (versions.version_id) from
versions), 'enable')"
This is the query before making the connection to the DB...
INSERT INTO intents (intent, version_id,status_intent) VALUES
('what?', (SELECT MAX (versions.version_id) from versions),
'enable')