I'm using expressjs and remote SQL DB. When I try to insert data, I keep getting an error that says: you have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use.
code: 'ER_PARSE_ERROR',
errno: 1064,
sqlState: '42000',
const sqlInsert =
'INSERT INTO employees (name, image, salary, role, status, typeEmployee ) VALUES ?,?,?,?,?,?';
try {
const newData = await db.query(sqlInsert, [
name,
image,
salary,
role,
status,
typeEmployee,
]);
res.status(200).json(newData);
} catch (error) {
console.log(error);
res.status(409).json({ message: `Employee want not added ${error}` });
}
CodePudding user response:
The ?
placeholders in the VALUES
clause of the insert need to appear inside parentheses, as a tuple (...)
:
const sqlInsert = `INSERT INTO employees (name, image, salary, role, status, typeEmployee)
VALUES (?,?,?,?,?,?)`;