2

My code looks like this

signup.post('/signup', urlendcodedParser, async(req: Request, res: Response) => {
    const username = req.body.username;
    const password = req.body.password;
    const age = req.body.age;
    const email = req.body.email;
    const fullname = req.body.fullname;
    console.log(req.body)
    
    await pool.query("INSERT INTO (username, userpassword, email, fullname, age) VALUES ($1, $2, $3, $4, $5) RETURNING *", [username, password ,email, fullname, age]).catch(err => console.log(err))
    await res.json("Akaunt napravljen")
})

But when I try to submit a POST request I get this error:

error: syntax error at or near "("
    at Parser.parseErrorMessage (C:\Users\prcap\Desktop\liveno-t\server\node_modules\pg-protocol\src\parser.ts:369:69)
    at Parser.handlePacket (C:\Users\prcap\Desktop\liveno-t\server\node_modules\pg-protocol\src\parser.ts:188:21)
    at Parser.parse (C:\Users\prcap\Desktop\liveno-t\server\node_modules\pg-protocol\src\parser.ts:103:30)
    at Socket.<anonymous> (C:\Users\prcap\Desktop\liveno-t\server\node_modules\pg-protocol\src\index.ts:7:48)
    at Socket.emit (events.js:375:28)
    at Socket.emit (domain.js:470:12)
    at addChunk (internal/streams/readable.js:290:12)
    at readableAddChunk (internal/streams/readable.js:265:9)
    at Socket.Readable.push (internal/streams/readable.js:204:10)
    at TCP.onStreamRead (internal/stream_base_commons.js:188:23) {
  length: 90,
  severity: 'ERROR',
  code: '42601',
  detail: undefined,
  hint: undefined,
  position: '13',
  internalPosition: undefined,
  internalQuery: undefined,
  where: undefined,
  schema: undefined,
  table: undefined,
  column: undefined,
  dataType: undefined,
  constraint: undefined,
  file: 'scan.l',
  line: '1180',
  routine: 'scanner_yyerror'
}

How can I fix this?

1
  • Your query is missing the name of the table that you want to insert into. Commented Jul 27, 2021 at 12:40

1 Answer 1

2

You're missing the table name.

INSERT INTO table_name (username, userpassword, email)...
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.