1
我是新手。我無法從前端插入數據到MySQL數據庫。我在插入時遇到問題。我無法找到與mysql代碼的錯誤
我index.js代碼
我存放在變量形式的細節,試圖將其插入到數據庫
router.post('/signup',function(req,res,next) {
var item = req.body;
connection.connect(function(err){
var sql = "INSERT INTO details VALUES ? ";
connection.query(sql,[item]);
});
res.render('data' ,{items:item});
});
錯誤消息
/home/gayathri/jsonhbs/node_modules/mysql/lib/protocol/Parser.js:80
throw err; // Rethrow non-MySQL errors
^
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 '`name` = 'Gayathri', `pwd` = 'def'' at line 1
at Query.Sequence._packetToError (/home/gayathri/jsonhbs/node_modules/mysql/lib/protocol/sequences/Sequence.js:52:14)
at Query.ErrorPacket (/home/gayathri/jsonhbs/node_modules/mysql/lib/protocol/sequences/Query.js:77:18)
at Protocol._parsePacket (/home/gayathri/jsonhbs/node_modules/mysql/lib/protocol/Protocol.js:279:23)
at Parser.write (/home/gayathri/jsonhbs/node_modules/mysql/lib/protocol/Parser.js:76:12)
at Protocol.write (/home/gayathri/jsonhbs/node_modules/mysql/lib/protocol/Protocol.js:39:16)
at Socket.<anonymous> (/home/gayathri/jsonhbs/node_modules/mysql/lib/Connection.js:103:28)
at emitOne (events.js:96:13)
at Socket.emit (events.js:188:7)
at readableAddChunk (_stream_readable.js:176:18)
at Socket.Readable.push (_stream_readable.js:134:10)
--------------------
at Protocol._enqueue (/home/gayathri/jsonhbs/node_modules/mysql/lib/protocol/Protocol.js:145:48)
at Connection.query (/home/gayathri/jsonhbs/node_modules/mysql/lib/Connection.js:208:25)
at Handshake._callback (/home/gayathri/jsonhbs/routes/index.js:46:14)
at Handshake.Sequence.end (/home/gayathri/jsonhbs/node_modules/mysql/lib/protocol/sequences/Sequence.js:88:24)
at /home/gayathri/jsonhbs/node_modules/mysql/lib/protocol/Protocol.js:225:14
at _combinedTickCallback (internal/process/next_tick.js:73:7)
at process._tickCallback (internal/process/next_tick.js:104:9)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] start: `node ./bin/www`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/gayathri/.npm/_logs/2017-10-18T03_54_05_403Z-debug.log
什麼_exactly_是'req.body'的內容? 「SHOW CREATE TABLE details」的MySQL輸出是什麼? – hunteke