我正在使用节点js,express和mysql。我的目标是将数据插入名为sbmtidea的表中,但是当我尝试执行代码时,我正在获取
undefined undefined undefined undefined
{ name: undefined,
email: undefined,
password: undefined,
phone: undefined }
{ Error: ER_BAD_NULL_ERROR: column 'name' cannot be null
我在这张表中没有任何名为name的列。列名在另一个表中。我检查了自动增量。但这也不起作用。我想我不会被引导到这张桌子上。
var express = require('express');
var router = express.Router();
var mysql = require('mysql');
var connection = mysql.createConnection({
host: 'localhost',
user: 'root',
password: '',
database:'backend',
})
/* our backend endpoint to check for users in the database */
router.post('/', function(req, res, next) {
console.log(' ');
var idea_group = req.body.idea_group;
var idea_category = req.body.idea_category;
var idea_title = req.body.idea_title;
var idea_detail = req.body.idea_detail;
console.log(idea_group,idea_category,idea_title,idea_detail);
var submitidea = {idea_group:idea_group,idea_category:idea_category,idea_title :idea_title,idea_detail: idea_detail};
connection.query("INSERT INTO sbmtidea set ?",submitidea,function(err,row,fields){
if (err) console.log(err);
});
});
module.exports = router;
这是我的反应原生代码:
constructor(props,context){
super(props,context);
this.state = {
idea_group: '',
idea_category: '',
idea_title:'',
idea_detail:'',
};
console.log();
}
submit = () => {
fetch('http://192.168.0.20:3000/submit_idea', {
method : 'POST',
headers: {
'Accept': 'application/json',
'Content-type': 'application/json',
},
body: JSON.stringify({
idea_group: this.state.idea_group,
idea_category: this.state.idea_category,
idea_title: this.state.idea_title,
idea_detail: this.state.idea_detail,
})
})
.then((response) => response.json())
.then((res) => {
if(res.success=== true){
var idea_group= res.message;
AsyncStorage.setItem('idea_title',idea_title);
Actions.Ideas();}
else {
alert(res.message);
}
})
.done();
}
请帮忙......