Reputation: 38
I'm using Node.js to run a MySQL command and get an error when inserting into the datatbase
const db = require("../db.js")
db.query('INSERT INTO subways (listing_id,name,distance,lines) VALUES (?,?,?,?)', [results[0]['listing_id'], closestStations[index].properties.name, distance.distance.text, closestStations[index].properties.line], function (error, subwayResults, fields) {
if (error) console.log(error)
})
And this is my error { Error: ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'lines) VALUES (179,'Wall St','89 ft','2-3')' at line 1
The code seems similar to the other insert commands
Upvotes: 0
Views: 37
Reputation: 133370
if your values is warpped by single quote and also your sql string is wrapped by single quote when the values are injected you obtain an invalid quote sequence try using double quote for sql code
const db = require("../db.js")
db.query("INSERT INTO subways (listing_id,name,distance,`lines`)
VALUES (?,?,?,?)", [results[0]['listing_id'],
closestStations[index].properties.name, distance.distance.text,
closestStations[index].properties.line], function (error, subwayResults, fields) {
if (error) console.log(error)
})
Upvotes: 2