const q = "INSERT INTO ?? (`text`,`url`) VALUES (?)";
const values = [req.body.text, req.body.url];
console.log(values);
console.log([tableName, ...values]); // did not worked
db.query(q, [tableName, values], (err, data) => {})
Code I tried I have shown above, I don't understand why it didn't work, I read about SELECT query in it tablename was passed using ??
, but I don't why it didn't work for INSERT query, can any explain why ? and also please what exactly ??
and ?
do here ?
I got tablename from frontend using req.params and stored in a varibale named as tableName and use its value in taableName but it didn't work, I got the idea to use ?? from an example of SELECT query, but I don't understand why it didn't work for INSERT query and want to know why? I was going to use this query to insert data into the table whose name I get from frontend so I don't have to write insert query for every table which has similar columns.
I got the following error: "Column count doesn't match value count at row 1",