gpt4 book ai didi

javascript - Nodejs (Javascript) 中的插入函数出现 MySQL 错误

转载 作者:行者123 更新时间:2023-11-29 10:51:09 24 4
gpt4 key购买 nike

我正在尝试使用插入功能,但我总是收到错误:(我正在尝试将用户名插入到用户表中

我的功能:

 function insert(tableName, toField, value){
connection.connect();
var queryString = "insert into "+tableName+" ("+toField+")
select "+connection.escape(value)+"";

connection.query(queryString, function(err) {
if (err) throw err;
});
}

在主代码中:

var name ="Anna";
Helpers.insert('user', 'name', name);

每次我收到错误时:

Uncaught exception: Error: ER_PARSE_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 ''user' ('name') select 'Anna'' at line 1
Error: ER_PARSE_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 ''user' ('name') select 'Anna'' at line 1

最佳答案

我成功了:)感谢您的帮助!

 function insert(tableName, toField, value){
connection.connect();
var queryString = "INSERT INTO "+tableName+" ("+toField+") VALUES ("+connection.escape(value)+")";

connection.query(queryString, function(err) {
if (err) throw err;
});
}

关于javascript - Nodejs (Javascript) 中的插入函数出现 MySQL 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43708505/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com