Why my database displays undefined even I inserted data in POSTMAN?(为什么即使我在 POSTMAN 中插入数据,我的数据库仍显示未定义?)
问题描述
下面是我在 ExpressJS 中的 MYSQL 中插入数据的代码.
Below is my code for inserting data in MYSQL in ExpressJS.
router.post('/user', function (req, res) {
let sql = "INSERT INTO Member (id, Memb_ID, First_Name, Middle_Name, Last_Name, Address, url) VALUES (null, '" + req.body.Memb_ID + "', '" + req.body.First_Name + "', '" + req.body.Middle_Name + "', '" + req.body.Last_Name + "', '" + req.body.Address + "', '" + req.body.url + "')";
myDB.query(sql, function (err, results) {
if (err) throw err;
res.send({
Success: "Data inserted."
})
});
});
它在我的数据库中插入数据,但我的数据库看起来像这样
It inserts data in my database but my database looks like this
我不知道为什么会这样输出.这是我的 JSON
I don't know why it outputs like that. Here's my JSON
编辑:这是我的 MYSQL 表
EDIT : Here is my MYSQL Table
推荐答案
你能确定下面的都做完了吗?
Can you make sure that the following is done?
请求中的
content-type标头必须是application/json
使用 body-parser(或类似库)来解析 JSON 负载 -> 您可以打印 req.body 来验证这一点.
Use body-parser (or similar libraries) to parse JSON payloads -> You can print the req.body to validate this.
如果您可以确认这些值是可访问的,我会建议转义查询值,如 https://github.com/mysqljs/mysql#escaping-query-values(或在您使用的任何 mysql 库中)——尤其是因为它是一个 DML 查询.
If you can confirm that the values are accessible, I would suggest escaping query values as mentioned in https://github.com/mysqljs/mysql#escaping-query-values (or in any mysql library that you use) - especially since it is a DML query.
(我还假设查询中使用的字段名与数据库中的字段名匹配,并且数据类型正确.)
(Also I assume that the fieldnames used in the query match with the ones in the database and are of the right datatype.)
这篇关于为什么即使我在 POSTMAN 中插入数据,我的数据库仍显示未定义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:为什么即使我在 POSTMAN 中插入数据,我的数据库仍显示未定义?
基础教程推荐
- 如何根据该 XML 中的值更新 SQL 中的 XML 2021-01-01
- oracle区分大小写的原因? 2021-01-01
- 在多列上分布任意行 2021-01-01
- MySQL 中的类型:BigInt(20) 与 Int(20) 2021-01-01
- 如何在 SQL 中将 Float 转换为 Varchar 2021-01-01
- 表 './mysql/proc' 被标记为崩溃,应该修复 2022-01-01
- mysql选择动态行值作为列名,另一列作为值 2021-01-01
- 在 MySQL 中:如何将表名作为存储过程和/或函数参数传递? 2021-01-01
- 二进制文件到 SQL 数据库 Apache Camel 2021-01-01
- 什么是 orradiag_<user>文件夹? 2022-01-01
