2

Hi I am working on mysql database with node js. Much of the data get inserted but at this point the query stuck, I don't know why. I tried mysql.escape() and utf8.encode() but still the same error.

This is my query

                ms_connect.query("INSERT INTO `companies_jobs` VALUES (null, '"+mysql.escape(data[i].title)+"','"+mysql.escape(data[i].link)+"','"+mysql.escape(data[i].date)+"','"+mysql.escape(data[i].level)+"','"+mysql.escape(data[i].category)+"','"+mysql.escape(data[i].function)+"','"+mysql.escape(data[i].loc)+"','"+mysql.escape(data[i].timing)+"','"+mysql.escape(data[i].company)+"','"+JSON.stringify(time)+"','"+JSON.stringify(date)+"',"+1+")", function(err, row){
                    if(err){
                        console.log(data[i]);
                        throw err;
                    } else{
                        i++;
                        s();
                    }
                })

I am trying to insert this data into the database :

[{
  category: 'Sales',
  company: '',
  date: 'Posted on 12/06/2018',
  function: '',
  level: 'Students',
  link: 'https://career5.successfactors.eu/career?career%5fns=job%5flisting&company=LiMySLive&navBarLevel=JOB%5fSEARCH&rcm%5fsite%5flocale=en%5fUS&career_job_req_id=13305&selected_lang=es_ES&jobAlertController_jobAlertId=&jobAlertController_jobAlertName=&_s.crb=fl08QG2oV1akJFW%2fWVQ4Ol50v%2bs%3d',
  loc: 'Chile (CL)',
  timing: 'full time',
  title: 'Alumno en Practica'
}]

But due to some reason, I get this 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 'Alumno en Practica'',''https://career5.successfactors.eu/career?career%5fns=job%' at line 1

This is how the table structure :

enter image description here

6
  • Add the table definition as text, please. Commented Dec 6, 2018 at 20:36
  • I see JSON.stringify(time) and JSON.stringify(date) in your query, but the key time is not included in the data you want to insert into the database. Did you perhaps mean JSON.stringify(data[i].timing) and JSON.stringify(data[i].date)? Commented Dec 6, 2018 at 20:40
  • no, date and time are separate Commented Dec 6, 2018 at 20:42
  • Done @Alfabravo Commented Dec 6, 2018 at 20:45
  • 'function' is a reserved word and one of your fields is using it: mysql.escape(data[i].function) Commented Dec 6, 2018 at 21:18

1 Answer 1

6

Looks like mysql.escape(data[i].title) is already putting single quotes around your values, so you're doubling that up by adding them yourself.

Sign up to request clarification or add additional context in comments.

1 Comment

Don't remove the scape, remove the single quotes you have in the string that you're explicitly putting in yourself.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.