为什么即使我在 POSTMAN 中插入数据,我的数据库也显示未定义? [英] Why my database displays undefined even I inserted data in POSTMAN?

查看:54
本文介绍了为什么即使我在 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

推荐答案

在您的邮递员呼叫图像中,它清楚地显示您的内容类型是text.

In your image of postman call, it's clearly showing your content type is text.

  1. 在邮递员呼叫标头中将 Content-type 更改为 application/json
  2. 或者您可以从正文选项卡中选择

由于您的正文内容是 text,如您的图像所示,它发送的是导致 DB 中未定义的纯文本.但是服务器需要 json.

As your body content was text as shown in your image, it was sending a plain text that leading to undefined in DB. But the server was expecting json.

希望有所帮助.

这篇关于为什么即使我在 POSTMAN 中插入数据,我的数据库也显示未定义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆