0

i'm try to find error from my code but i dont know what i wrong. Can Anyone see some error on it?

const {Client} = require('pg');
const client = new Client({
user: 'me',
host: 'localhost',
database: 'printer',
password: '1234',
port: 5432,
});

client.connect(function(err){
if (err) throw err
console.log("Connected Successfuly");
console.log("****if you want to stop this service, press Ctrl + C****");

var datain ='{"filename" : "filetest01.pdf","printer" : "Microsoft Print to PDF","address" : "C:\\Users\\parun\\Desktop\\printer\\printerserver\\photo","date" : "2020-11-23T17:00:00.000Z","status" : 1}';
var sql = 'INSERT INTO print(filename, printer, address, date, status) VALUES(?, ?, ?, ?, ?)';

client.query(sql, [datain.filename, datain.printer, datain.address, datain.date, datain.status],(err, result) => {
        if (err)
            throw err;
        console.table(result.rows);
    });
});
6
  • 1
    Do you have any additional output? Commented Nov 30, 2020 at 4:33
  • 1
    datain is a string so datain.whatever will only ever be undefined. Remove the single-quotes if you want an actual object Commented Nov 30, 2020 at 4:36
  • @richyen no, i only have pg Commented Nov 30, 2020 at 4:55
  • @Phil ok, now im try t edit follow your comment but it's dont work and send me back to same my error Commented Nov 30, 2020 at 5:04
  • Can you indicate which line and column the error is at? Its easier to just post the full error stack trace Commented Nov 30, 2020 at 5:09

1 Answer 1

1

change your sql

var sql = 'INSERT INTO print(filename, printer, address, date, status) VALUES($1, $2, $3, $4, $5)';
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.