Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why is this SQL syntax wrong?

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,

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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}` });
  }

>Solution :

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 (?,?,?,?,?,?)`;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading