'Error: You have an error in your SQL syntax; near 'order(total,userId) VALUES(?,?)' at line 1

I am newish in mysql and trying to insert a new order in order table , I have checked the mysql docs and npm/mysql2 docs and i couldn't reach to anything. this is my middleware

router.post('/addorder', requireAuth , [
  body('totalPrice').isFloat({gt :0}).not().isEmpty().withMessage('Total price must be provided and greater than 0'),
  body('products').isArray({min : 1}).withMessage('Purchased products must be provided')
], validateRequest, async(req,res) =>{
  const userId = req.currentUser.id ;
  const {products , totalPrice} = req.body ;
  console.log(parseFloat(totalPrice));
  console.log(userId);
  await db.execute('INSERT INTO order(total,userId) VALUES(?,?)',[totalPrice,userId]);
  const [rows,fields] =await db.execute('SELECT orderId FROM order WHERE userId=? ORDER BY orderId DESC',[userId]);
  const {orderId} = rows[0];
  products.forEach(async (product) =>{
    await db.execute('INSERT INTO order-product(order_id , product_id) VALUES(?,?)',[orderId , product.productId]);
    const [rows,field] = await db.execute('SELECT quantity FROM product WHERE productId = ?',[product.productId]);
    const {quantity} = rows[0];
    const updatedQuantity = quantity - product.number ;
    await db.execute('UPDATE product SET quantity=? WHERE productId = ?',[updatedQuantity , product.productId])
  });

  res.status(201).send({success: true});
});

this is my table schema enter image description here

and this is the full error with logged values of totalPrice and userId

4.55
1
(node:8464) UnhandledPromiseRejectionWarning: Error: 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 'order(total,userId) VALUES(?,?)' at line 1
    at PromisePool.execute (C:\Users\Mohamed Salah\Desktop\Ecommerce App\node_modules\mysql2\promise.js:359:22)
    at C:\Users\Mohamed Salah\Desktop\Ecommerce App\routes\orders.js:17:12
    at Layer.handle [as handle_request] (C:\Users\Mohamed Salah\Desktop\Ecommerce App\node_modules\express\lib\router\layer.js:95:5)
    at next (C:\Users\Mohamed Salah\Desktop\Ecommerce App\node_modules\express\lib\router\route.js:144:13)
    at validateRequest (C:\Users\Mohamed Salah\Desktop\Ecommerce App\middlewares\validateRequest.js:9:3)
    at Layer.handle [as handle_request] (C:\Users\Mohamed Salah\Desktop\Ecommerce App\node_modules\express\lib\router\layer.js:95:5)
    at next (C:\Users\Mohamed Salah\Desktop\Ecommerce App\node_modules\express\lib\router\route.js:144:13)
    at middleware (C:\Users\Mohamed Salah\Desktop\Ecommerce App\node_modules\express-validator\src\middlewares\check.js:16:13)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
(node:8464) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source