0

I am trying to get a password entered from my web application, hash it and send it to my database. Right now all is done in localhost.

I have been following a tutorial for the most part, the main difference being their database is mysql while I am using postgresql which I'm assuming is why I am having an error.

It is breaking down when I call db.query.

db.query(
  "INSERT INTO passwords (user_id, secure_password, iv, created_by) VALUES(?,?,?,?);",
  [1058083062,hashedPassword.password, hashedPassword.iv, 1058083062],
  (err,result) => {
      if (err) {
          console.log(err);
      } else {
          res.send("Success");
      }
  }

)

This is what db looks like:

const pg = require('pg');
const secret = require('./secret');

const db = new pg.Pool({
  user: secret.db_user,
  password: secret.db_password,
  host: secret.db_host,
  port: secret.db_port,
  database: secret.db_database,
});

module.exports = db;

I am getting this error:

error: syntax error at or near ","

with err showing:

{"length":90,"name":"error","severity":"ERROR","code":"42601","position":"74","file":"scan.l","line":"1180","routine":"scanner_yyerror"}

1 Answer 1

1

Try

db.query(`INSERT INTO passwords (user_id, secure_password, iv, created_by) VALUES($1,$2,$3,$4)`,
  [1058083062,hashedPassword.password, hashedPassword.iv, 1058083062],
  (err,result) => {
      if (err) {
          console.log(err);
      } else {
          res.send("Success");
      }
  }
)

Notice we changed the ?,?,?,? to $1,$2,$3,$4 for param query

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

Comments

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.