我已经尝试了一个星期,以便能够将更改写入MySQL数据库,但最终我做到了,但是出现404错误,程序崩溃了,我在做什么错了,这是代码..
router.post('/edit', (req, res) => {
const {
user_id = req.params.user_id,
timesPD = req.body.timesPD,
chkCarbs = req.body.chkCarbs,
chkInsulin = req.body.chkInsulin,
typInsulin = req.body.typInsulin,
chkBP = req.body.chkBP
} = req.query;
const sql =
`UPDATE preferences
SET user_id=${user_id}, timesPD=${timesPD}, chkCarbs=${chkCarbs},
chkInsulin=${chkInsulin}, typInsulin=${typInsulin}, chkBP=${chkBP}
WHERE user_id=${user_id};`;
connection.query(sql,
[user_id, timesPD, chkCarbs, chkInsulin, typInsulin, chkBP],
(err, results) => {
if (err) {
return res.send(err.message);
} else {
res.send('Rows affected: ', results.affetedRows);
}
}
);
});
我正在使用12.14.1版的节点,并且得到的终端错误是
RangeError [ERR_HTTP_INVALID_STATUS_CODE]: Invalid status code: Rows
affected:
[0] at ServerResponse.writeHead (_http_server.js:246:11)
[0] at ServerResponse._implicitHeader (_http_server.js:237:8)
[0] at ServerResponse.end (_http_outgoing.js:720:10)
[0] at ServerResponse.send
(D:\vscode\bgtracker\node_modules\express\lib\response.js:221:10)
[0] at Query.<anonymous>
(D:\vscode\bgtracker\routes\preferences.js:90:13)
[0] at Query.<anonymous>
(D:\vscode\bgtracker\node_modules\mysql\lib\Connection.js:525:10)
[0] at Query._callback
(D:\vscode\bgtracker\node_modules\mysql\lib\Connection.js:491:16)
[0] at Query.Sequence.end
(D:\ vscode \ bgtracker \ node_modules \ mysql \ lib \ protocol \ sequences \ Sequence.js:83:24) Query._handleFinalResultPacket上的[0](D:\ vscode \ bgtracker \ node_modules \ mysql \ lib \ protocol \ sequences \ Query.js:139:8) [0]在Query.OkPacket上(D:\ vscode \ bgtracker \ node_modules \ mysql \ lib \ protocol \ sequences \ Query.js:72:10){ [0]代码:“ ERR_HTTP_INVALID_STATUS_CODE”