var express = require('express');
var app = express();
var pg = require('pg');
var connectionString = "postgresql://postgres:sujay123@localhost:3001/redc";
app.use(express.static('public'));
app.get('/index.html', function (req, res) {
res.sendFile( __dirname + "/" + "index.html" );
})
app.get('/process_get', function (req, res) {
response = {
name:req.query.name,
lat:req.query.lat,
long1:req.query.long
};
console.log(response);
res.end(JSON.stringify(response));
var client = new pg.Client(connectionString);
client.connect();
console.log("connect");
console.log("INSERT INTO data(name, latitude,longitude) values('"+req.query.name+"',"+req.query.lat+","+req.query.long+")");
var i = client.query("INSERT INTO data values('"+req.query.name+"',"+req.query.lat+","+req.query.long+")");
console.log(i);
console.log("Query Inserted")
})
var server = app.listen(3001, function () {
var host = server.address().address
var port = server.address().port
console.log("Example app listening at http://%s:%s", host, port)
})
我正在获取此代码并运行但是当我检查数据库时,插入查询没有工作,并且3个参数中的值即将出现名称,lat和long只是查询无法正常工作。
答案 0 :(得分:1)
是的,插入语法错误。您在控制台中登录的查询看起来是正确的,但它与您在数据库查询中使用的字符串不同。