er\u parse\u错误javascript

vfhzx4xs  于 2021-06-23  发布在  Mysql
关注(0)|答案(1)|浏览(252)

我有以下脚本:

radioStation.on('metadata', function(metadata) {
    var values = (metadata.StreamTitle).split('-').map(i=>i.trim());
    var artist = values[0];
    var title = values[1];
    console.log('webstream');
    console.log(artist); 
    console.log(title);  

    var con = mysql.createConnection({
      host: "localhost",
      user: "root",
      password: "",
      database: "radio"
    });

    con.connect(function(err) {
      if (err) throw err;
      console.log("Connected!");

      var sql = "INSERT INTO webstream (artist, title) VALUES ( " + artist + " ," + title + ")";
      //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

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

当我执行脚本时,我会得到一个er\u parse\u错误。
有人知道我做错了什么吗?

mrwjdhj3

mrwjdhj31#

@史蒂夫在正确的轨道上。也许这会有帮助:

var sql = "INSERT INTO webstream (artist, title) VALUES ( '" + artist + "', '" + title + "')";

相关问题