I am using node js, express and mysql. My goal in to insert data into a table called sbmtidea, but when i try to execute the code i am getting
undefined undefined undefined undefined
{ name: undefined,
email: undefined,
password: undefined,
phone: undefined }
{ Error: ER_BAD_NULL_ERROR: column 'name' cannot be null
I don't have any column called name in this table. The column name is in another table. I checked for auto increments. But that doesn't work either. I think i am not being directed to this table.
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;
This is my react native code:
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();
}
Please help...
via Avikrit Khati
No comments:
Post a Comment