我在 pgAdmin 4 上创建了一个数据库,但是当通过 Node 上的注册表单发送时,值没有更新。另外 npm install postgre-sql 给出了一个错误
var express = require('express');
var router = express.Router();
const { Pool,Client} = require('pg')
const connectionString='postgressql://postgres:12345@@localhost:5432/postgres'
const client= new Client({
connectionString:connectionString
})
client.connect()
/* GET home page. */
router.get('/', function(req, res, next) {
res.render('index', { title: 'Express' });
});
router.post('/action',function(req,res){
var uname= req.query.username;
var pass= req.query.psw;
var em= req.query.email;
var DOB=req.query.dob;
var gen= req.query.gender;
client.query('INSERT INTO SIGNUP(username,email,password,DOB,gender) VALUES ("'+uname+'", "'+em+'", "'+pass+'","'+DOB+'","'+gen+'")',(err,res)=>{
console.log(err,res)
client.end()
} )
})
module.exports = router;
最佳答案
看起来你可能有错别字 postgressql://postgres:12345@@localhost:5432/postgres
应该是postgresql://postgres:12345@@localhost:5432/postgres
关于node.js - 值没有被插入到 PostgreSQL 数据库中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57521488/