gpt4 book ai didi

node.js - 值没有被插入到 PostgreSQL 数据库中

转载 作者:行者123 更新时间:2023-11-29 13:39:25 25 4
gpt4 key购买 nike

我在 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com