Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 我使用NodeJS将值从html文件插入sql server,但它在sql server数据库下显示为未定义的值_Javascript_Node.js_Sql Server - Fatal编程技术网

Javascript 我使用NodeJS将值从html文件插入sql server,但它在sql server数据库下显示为未定义的值

Javascript 我使用NodeJS将值从html文件插入sql server,但它在sql server数据库下显示为未定义的值,javascript,node.js,sql-server,Javascript,Node.js,Sql Server,在下面的WebForm中填写信息并提交数据后,我在ms sql server记录下获得了未定义的值 //我的html文件 <!doctype html> <html lang="en"> <head> <title>Employees</title> <!-- Required meta tags --> <meta charset="utf-8"&g

在下面的WebForm中填写信息并提交数据后,我在ms sql server记录下获得了未定义的值

//我的html文件

<!doctype html>
<html lang="en">
  <head>
    <title>Employees</title>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

   
  </head>
  <body>
    <h1><center>Add a new Employee</center></h1><br>

    <center>
      <form action = "http://localhost:8080/api" method = "POST" enctype = "multipart/form-data">
         <input type ="text" name ="first_Name" placeholder="Enter First Name"><br>
         <br>
         <input type ="text" name = "last_name" placeholder="Enter Last Name"><br>
        
         <input type = "submit" value = "Submit">
      </form><br>
    </center>

    
    <!-- Optional JavaScript -->
      <script src="Node.js"></script>
   
  </body>
</html>
在SQL server下显示记录后,我发现我提交的数据为“未定义”,并且不是我在webform中提交的数据,请说明我的代码中有什么错误

请举例说明如何解决这种情况


非常感谢

您正在使用的表单数据中有输入错误

var query = "INSERT INTO test.dbo.name (First_Name,Last_name) VALUES ('" +req.body.First_Name+"','"+req.body.Last_name+"')";
应该是,

var query = "INSERT INTO test.dbo.name (First_Name,Last_name) VALUES ('" +req.body.first_Name +"','"+req.body.last_name+"')";

我根据您的共享评论进行了更改,但问题仍然是一样的。当调用post api时,您在日志中看到了什么,请查看日志中的req参数。app.post(“/api”),函数(req,res){
var query = "INSERT INTO test.dbo.name (First_Name,Last_name) VALUES ('" +req.body.first_Name +"','"+req.body.last_name+"')";