title: How to insert express js | Node js values into the database
body: <p>I have the following code contain image upload and handling input text. I have to insert this values into the mysql database. I can't insert multiple values into the database. But I can even a single row values... </p>
  
  <p>I can insert this response </p>
  
  <pre><code>{"name":"As","age":"12","imagePic":["userPic-1473665739434.jpeg"]}
  </code></pre>
  
  <p>I can't insert this response </p>
  
  <pre><code>{"name":["As","bs"],"age":["12","13"],"imagePic":["userPic-1473663782550.jpeg","userPic-1473663782628.jpeg"]}
  </code></pre>
  
  <hr>
  
  <pre><code>var express = require('express');
  var multer  =   require('multer');
  var mime    =   require('mime');
  var mysql = require('mysql');
  var app = express();
  var bodyParser =    require("body-parser");
  app.use(bodyParser.urlencoded({ extended: true }));
  app.use(bodyParser.json());
  
  var connection = mysql.createConnection({
    host     : 'localhost',
    user     : 'root',
    port      : 3306,
    password : '',
    database : 'test'
  });
  
  connection.connect(function(err){
  if(!err) {
      console.log("Database is connected ... nn");    
  } else {
      console.log("Error connecting database ... nn");    
  }
  });
  
  var storage =   multer.diskStorage({
    destination: function (req, file, callback) {
      callback(null, './uploads');
    },
    filename: function (req, file, callback) {
      callback(null, file.fieldname + '-' + Date.now() + '.' + mime.extension(file.mimetype));
    }
  });
  var upload = multer({ storage : storage }).array('userPic');
  
  app.get('/completeForm.html', function(req, res){
      res.sendFile(__dirname + '/' + 'completeForm.html')
  });
  
  app.post("/postFormAct", function (req, res, next) {
      upload(req,res,function(err) {
          /*console.log(req.body.user);
          console.log(req.body.email);
          console.log(req.files);*/
          var imgName = [];
          for(var i=0; i&lt;req.files.length; i++) {
              imgName[i] = req.files[i].filename;
          }
          response = {
          name : req.body.user, 
          age : req.body.email, 
          imagePic : imgName
          };
          // res.send(JSON.stringify(response)); sample response eg: {"name":["As","bs"],"age":["12","13"],"imagePic":["userPic-1473663782550.jpeg","userPic-1473663782628.jpeg"]}
          if(!err) {
  
              connection.query('INSERT INTO nodetable SET ?',[response], function(err, result){
                  if(!err) {
                  res.send(response);
                  }
                  else{
                  throw err;
                  }
              });
          } 
          else {
              throw err;
          } 
  
      });
  
  });
  
  app.listen(3000);
  </code></pre>
  
  <p>Html code given below </p>
  
  <pre><code>&lt;script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"&gt;&lt;/script&gt;
  &lt;form method="post" action="/postFormAct" enctype="multipart/form-data"&gt;
      &lt;input type="text" name="user"&gt;&lt;br&gt;
      &lt;input type="text" name="email"&gt;&lt;br&gt;
      &lt;input type="file" name="userPic"&gt;&lt;br&gt;
      &lt;div id="appendMore"&gt;&lt;/div&gt;
      &lt;input type="submit" value="Submit"&gt;&lt;input type="button" value="Add More Fields" id="clickBtn"&gt;
  &lt;/form&gt;
  &lt;script&gt;
      $(document).ready(function() {
      $("#clickBtn").click(function(){
          $("#appendMore").append('&lt;input type="text" name="user"&gt;&lt;br&gt;&lt;input type="text" name="email"&gt;&lt;br&gt;&lt;input type="file" name="userPic"&gt;&lt;br&gt;');   
      });
      });
  &lt;/script&gt;
  </code></pre>
  
  <p>Database structure shown below </p>
  
  <p><a href="https://i.stack.imgur.com/Ulz0P.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Ulz0P.png" alt="enter image description here"></a></p>
  
  <p>Please anybody help ...</p>