title: How to insert into a SQL table using a for-loop in NodeJS?
body: <p>I am having trouble finding the proper SQL syntax on adding items to my table using a for loops and an array. This is what I am trying to do: </p>
  
  <pre><code>var mysql = require('mysql');
  
  var con = mysql.createConnection({
      host: "localhost",
      user: "root",
      database: 'DUSAgeocodeDB'
  });
  
  var addreses = ['addres1', 'address2', 'address3'];
  var latitude = [12, 45, 789];
  var longitude = [987, 654, 321];
  
  for (var i =0; i &lt;addreses.length; i++) {
  
      con.connect(function(err) {
          con.query(`INSERT INTO maintable (mainaddress, latitude, longitude) VALUES (${addreses[i]}, ${latitude[i]}, ${longitude[i]} )`, function (err, result) {
              if(err) throw err;
  
              console.log('VALUES ADDED')
          });
  
      })
  }
  
  </code></pre>
  
  <p>What would be the proper syntax on the con.query() statement in order to save those values to mysql table? This is something else that I've tried but it does not work </p>
  
  <pre><code>for (var i =0; i &lt;addreses.length; i++) {
  
      con.connect(function(err) {
          con.query("INSERT INTO maintable (mainaddress, latitude, longitude) VALUES ("+${mysql.escape(addreses[i])}+", "+${mysql.escape(latitude[i])}+", "+${mysql.escape(longitude[i])}" )", function (err, result) {
              if(err) throw err;
  
              console.log('VALUES ADDED')
          });
  
      })
  }
  </code></pre>