Hi, I am trying to add an array to a table in MySQL with nodejs. Is it possible to do this? I have the below code, it works if there is only one item in the array, but will give me the syntax error: “ER_WRONG_VALUE_COUNT_ON_ROW” if there is more items.
Is it possible to insert all the array values in the table? If so, how can it be done?
The code:
let workoutArray = [];
result.forEach(function(name) {
workoutArray.push(name.exercise);
});
let sql2 = 'INSERT INTO reps (email, date, workout, exercise) VALUES (?,?,?,?)';
connection.query(sql2, [user, addDate, workoutToIndex, workoutArray], function (error2, result2) {
if (error2) throw error2;
console.log(result2);
});