Been 2 days trying to find a solution to my problem. I request data(json) from a website. They return fine and json is valid but when i try to insert them to database almost 10% do not get inserted. I dont know what to do, i even tried php with same results. Any help world be appreciated thank you.
This is json ouptut after selecting the data attribute var result = obj.data; pastebin
var request = require("request");
var fs = require('fs');
var sleep = require('system-sleep');
var mysql = require('mysql');
var connection = mysql.createConnection({
host: 'localhost',
user: 'root',
password: '',
database: 'feeds',
timezone: 'Z'
});
request.post({
url: "xxx",
headers: {
"Content-Type": "application/json"
},
body: '{"xx": "true", "xxx": "true"}'
}, function(error, response, body) {
var obj = JSON.parse(body);
var result = obj.data;
console.log(result);
for (var i = 0; i < result.length; i++) {
var object = result[i];
for (property in object) {
var value = object[property];
var pid, pname;
if (property == "id") {
pid = value;
}
if (property == "name") {
pname = value;
}
if (property == "xxxxx") {}
if (property == "xxxxxxxx") {
connection.query('INSERT INTO tournaments(id, name) VALUES (' + pid + ', "' + pname + '")');
}
}
}
});