ER_PARSE_ERROR node.js 和 mysql 问题(插入)

ER_PARSE_ERROR node.js and mysql issue (INSERT INTO)

我想在 socket.io 与 node.js 和 MySQL 一起使用时用 Node.js 做一个简单的插入。不知道为什么,但我收到此错误

You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''markos'' at line 1

我的代码:
当我尝试这样做时,出现上述错误。

io.on("connection", function(socket){
console.log("a user is connected " + socket.id );


    socket.on("question", function (question){

        let sql = "INSERT INTO nodeJs (name) VALUES ?";

        con.query(sql, question, function (err) {
            if (err) throw err;
            console.log("1 record inserted");
        });


    });

  });
});

如果我尝试这个简单的代码,一切正常:

io.on("connection", function(socket){
console.log("a user is connected " + socket.id );


    socket.on("question", function (question){

        let sql = "INSERT INTO nodeJs (name) VALUES ('John')";

        con.query(sql, function (err) {
            if (err) throw err;
            console.log("1 record inserted");
        });

    });

 });
});

问题参数总是有一个字符串。

您缺少值周围的括号:

let sql = "INSERT INTO nodeJs (name) VALUES (?)";
// Here ------------------------------------^-^