I got undefined values when I send these values to the api. Note : I use postman and it works good . this is my code on react app
submithandler=(e)=>{
e.preventDefault();
axios.post('http://localhost:8000/api/addsickers',
JSON.stringify({
ID:"123456789",
Blod:"22334445",
Allergic:"6677788",
Chronic:"3445566"
})
)
.then(response=>{
alert(response);
})
.catch(err=>{
alert("catch"+err);
});
}
and this is the api code :
var person = req.body;
/* const schema = joi.object().keys({
ID: joi.string().min(5).max(50).required(),
Blod: joi.string().required(),
Allergic: joi.string(),
Chronic: joi.string(),
});*/
// validate data
// if (!joi.validate(person, schema)) {
con.connect();
con.query('INSERT INTO `sick`(`ID`, `Blod`, `Allergic`, `Chronic`) VALUES ("' + person.ID + '","' + person.Blod + '","' + person.Allergic + '","' + person.Chronic + '")', function(err, rows, fields) {
if (err) {
// res.send(toString(err));
console.log(err);
}
// res.send("registred succefully");
})
// } else {
// res.send("please validate your data");
//}
//ID + Blod + allergic + chronic +
con.end()
console.log(req.body);
Note : the console.log(person) shows me a json array that means data has transfared . but in insert it s defined , for example "person.ID" is undefined . the question is how to get non undefined values from this json array . cause I tried some methods and does not work for me . thanks in advance.