dimanche 14 août 2016

MYSQL Node.JS Error

Im creating a daemon that automatically changes MYSQL table contents randomly around my pages. (wordpress tables)

I have a array of stories that the system will read and then UPDATE the mysql in the tables, and as well update the timestamp on the server.

My code looks like this

//required libraries
fs = require('fs')
var mysql = require('mysql');
var dateFormat = require('dateformat');
var now = new Date();

//mysql table
var connection = mysql.createConnection({
  host     : 'yomamabinshoppin',
  user     : 'nonya',
  password : 'defineltynonya',
  database : 'okbye'
});


connection.connect();


//sitelisting
var sites = [ 'wp_counlwarehouseposts', 'wp_infounlwarehouseposts', 'wp_infowarehouse31posts', 'wp_netunlwarehouseposts', 'wp_netwarehouse31posts', 'wp_orgunlwarehouseposts', 'wp_orgwarehouse31posts', 'wp_stagcomwarehouseposts', 'wp_stagcowarehouseposts', 'wp_staginfwarehouseposts', 'wp_stagnetwarehouseposts', 'wp_stagorgwarehouseposts'];

//select story from catalogue
function ss (id,callback){
    fs.readFile('./' + id +'.txt', 'utf8', function (err,data) {
   callback(data);
});}

sites.forEach(function(entry) {
    ss(Math.floor(Math.random() * 12), function (returnvalue){
    fs.writeFile(entry, returnvalue);
    connection.query("UPDATE  `warehous_wordpress`.`"+entry+"` SET  `post_date` =  '"+ dateFormat(now, "yyyy-m-d") +" 01:00:01' WHERE `"+entry+"`.`ID` =1", function(err, rows, fields) {

 if (err) throw err;


});
 fs.appendFile('postlog.log', "UPDATE `warehous_wordpress`.`"+entry+"` SET `post_content` = '"+returnvalue+"' WHERE `"+entry+"`.`ID` = 1" , function (err) {

});
connection.query("UPDATE `warehous_wordpress`.`"+entry+"` SET `post_content` = '"+returnvalue+"' WHERE `"+entry+"`.`ID` = 1", function(err, rows, fields) {

 if (err) throw err;
 });

});


});

The issue in question here is at the line of

fs.appendFile('postlog.log', "UPDATE `warehous_wordpress`.`"+entry+"` SET `post_content` = '"+returnvalue+"' WHERE `"+entry+"`.`ID` = 1" , function (err) {

});

Where returnvalue is my story, and where entry is the current table name.

Error: ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual th
at corresponds to your MySQL server version for the right syntax to use near 're
 frightened can become a safety issue. When designing something to scare visit'
at line 1

The story that it is referring to has the text of this.

SCARE PEOPLE THE RIGHT WAY.
"We always try to scare forward to try to keep the flow going," Travis says. "A lot of times we try to scare further down the path rather than being scared into the wall," which slows the circulation of traffic through the maze.
Plus, where people instinctively move when they're frightened can become a safety issue. When designing something to scare visitors, you have to think about how people will react—and what they might jump into if they leaped backward in terror. "You never really know how bad something is going to scare somebody," Travis explains. "We try to keep the opposite wall clear from any kind of metal props or anything like that."

At first i thought the issue was related to some html in my stories, so i removed ALL of the html in the stories, same issue was happening.

Any advice to how i could fix this? Thank you.




Aucun commentaire:

Enregistrer un commentaire