Javascript 创建用户API Mysql自动增量错误
我正在尝试运行一个简单的create user函数,但一直都会遇到一个奇怪的sql错误,我假设这个错误来自于我使用mysql的auto increment键时出现的某种错误,但一直无法确定实际的问题 下面是我的服务器代码示例:Javascript 创建用户API Mysql自动增量错误,javascript,mysql,api,Javascript,Mysql,Api,我正在尝试运行一个简单的create user函数,但一直都会遇到一个奇怪的sql错误,我假设这个错误来自于我使用mysql的auto increment键时出现的某种错误,但一直无法确定实际的问题 下面是我的服务器代码示例: app.post('/createPhysician', function(req, res) { console.log(req.body); // do input checking here var createPromise = inter
app.post('/createPhysician', function(req, res) {
console.log(req.body);
// do input checking here
var createPromise = interact.createPhysician(req.body.physicianID,
req.body.firstName,
req.body.lastName,
req.body.yearNum,
req.body.position,
req.body.isAttending,
req.body.highRiskTrained)
//did promise
createPromise.then(function(createResponse) {
res.status(200).json({"status":"success"}); // .end because we just want to return an empty response
}).catch(function(err) {
console.log(err);
res.status(500).json(err);
});
});
以下是func的interact.sql代码:
createPhysician: function(
firstName,
lastName,
yearNum,
position,
isAttending,
highRiskTrained) {
var qry = "insert into Physician (firstName, lastName, yearNum, position, isAttending, highRiskTrained) values \
('"+firstName+"', '"+lastName+"', "+yearNum+", '"+position+"', "+isAttending+", "+highRiskTrained+");";
return runQuery(qry);
}
下面是我的mysql表的说明:
下面是我为《邮递员》中的一具尸体输入的内容:
{
"firstName": "firstName",
"lastName": "lastName",
"yearNum": 1,
"position": "coder",
"isAttending": 1,
"highRiskTrained": 0
}
以下是我从邮递员请求中得到的错误:
{
"code": "ER_BAD_FIELD_ERROR",
"errno": 1054,
"sqlMessage": "Unknown column 'coder' in 'field list'",
"sqlState": "42S22",
"index": 0,
"sql": "insert into Physician (firstName, lastName, yearNum, position, isAttending, highRiskTrained) values ('undefined', 'firstName', lastName, '1', coder, 1);"
}
请求正文的API控制台日志输出如下:
{ firstName: 'firstName',
lastName: 'lastName',
yearNum: 1,
position: 'coder',
isAttending: 1,
highRiskTrained: 0 }
使用函数包装查询时,请确保查询使用了正确的参数,并将其正确地传递到函数中
把一个正式的答案放在最后仅仅是一个打字错误上总是让人觉得有点奇怪,但我想你永远不知道谁可能需要指出同样的打字错误。错误表明你的表中没有列
coder
。正如您也可以在发布的表的图像中看到一样。但是说实话,我仍然不明白为什么会在这里抛出这个错误,因为您将coder
作为一个值传递,而不是作为一个列传递…app.post('/createmedicine',function(req,res){console.log(req.body)
你能发布这个控制台输出吗?你甚至应该将physicianId
传递到CreateMedicine
函数中吗?看起来它没有定义这样的参数,这样做会“移动”你传递的值,这就是为什么“lastName”和“coder”结果没有分隔符;并且highRiskTrained的值甚至没有包含在查询中。@messerbill这就是为什么我也感到困惑的原因,就像sql只是将单引号向下移动了一个参数……我还发布了该console.log()的输出
它似乎打印了预期的值…@uuerdo我已经忽略了这几天了!!!删除它修复了它!