Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

131
Views
Can not write data into mySql from node.js

Before I have made a test run and Everything was ok, but know when I am trying to insert a new static data it is saying that result is undefined. How to solve this? error from terminal

const mysql = require("mysql")
const con = mysql.createConnection({
    host:"localhost",
    user:"root",
    password:"",
    database:"magebitdb"
});

con.connect((err)=>{
    if(err) throw err;
    console.log("connected to DB");
    

    // const sql =`INSERT INTO subscribers(email) VALUES (${email})`;
    const sqlInsert = ("INSERT INTO subscribers(email) VALUES ?")
    const values=[
        "test value"
    ]
    con.query(sqlInsert,[values],(err,result)=>{
        console.log(`inserted data is: ${result}`);
        console.log(values);
    });
});

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I have found the solution for this error.

I have console logged err in con.query and I noticed that in error there was no brackets and it was causing an error in the SQL syntax.

Basically I added brackets to sqlInsert and it worked const sqlInsert = ("INSERT INTO subscribers(email) VALUES (?)")

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!