Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 通过搜索按钮使用节点js将数据库中的数据检索到html中_Javascript_Html_Node.js - Fatal编程技术网

Javascript 通过搜索按钮使用节点js将数据库中的数据检索到html中

Javascript 通过搜索按钮使用节点js将数据库中的数据检索到html中,javascript,html,node.js,Javascript,Html,Node.js,我想根据“搜索”按钮从数据库中的(调查、名称、地点)等列将数据显示到html表格行中。我想根据调查结果搜索数据 我在sql选择部分有错误: var express = require('express'); var connect = require("connect") app = express().use(express.static(__dirname + '/db')), http = require('http').Server(app); const { Pool, Cli

我想根据“搜索”按钮从数据库中的(调查、名称、地点)等列将数据显示到html表格行中。我想根据调查结果搜索数据

我在sql选择部分有错误:


var express = require('express');
var connect = require("connect")


app = express().use(express.static(__dirname + '/db')),
http = require('http').Server(app);

const { Pool, Client } = require('pg')
const connectionString = 'postgresql://postgres:postgr@localhost:5432/apb_cad'
const pool = new Pool({
  connectionString: connectionString,
})
app.engine('html', require('ejs').renderFile);
app.set('view engine', 'html');
app.get('/search', function (req, res, next) {
  if(req.method === "POST"){
       pool.query('SELECT survey_n_1,lulc,gm FROM table',function(err,rows,fields) {
           if(err){
               console.log(err);
               res.status(400).send(err);
           }
res.render('home.html',{data: rows.rows});

       });
     }
    });


app.listen(4000, function () {
    console.log('Server is running.. on Port 4000');
});

<form class="example" action="/search" method="POST">
  <input type="text" placeholder="Search..">
  <button type="submit"  value="Submit"><i class="fa fa-search"></i></button>
</form>

<table>
    <th>Surevy N</th>
    <th>L</th>
    <th>G</th>

  <tr>
    <% for(var i=0; i< data.length; i++) { %>
                <td><%= data[i].survey_n%></td>
                <td><%= data[i].lu%></td>
                <td><%= data[i].g%></td>  
            </tr>
            <% } %>
</table>



var express=需要(“express”);
var connect=需要(“连接”)
app=express(),
http=require('http')。服务器(应用程序);
const{Pool,Client}=require('pg')
常量connectionString='postgresql://postgres:postgr@本地主机:5432/apb_cad'
常量池=新池({
connectionString:connectionString,
})
app.engine('html',require('ejs').renderFile);
app.set('view engine','html');
app.get('/search',函数(req,res,next){
如果(请求方法==“POST”){
pool.query('SELECT survey\n\u 1,lulc,gm FROM table',函数(err,rows,fields){
如果(错误){
控制台日志(err);
资源状态(400)。发送(错误);
}
res.render('home.html',{data:rows.rows});
});
}
});
应用程序侦听(4000,函数(){
log('服务器正在运行..在端口4000上');
});
苏维
L
G
表是,你不能那样使用它

替换此行:

pool.query('SELECT survey_n_1,lulc,gm FROM table',function(err,rows,fields) {
作者:

更好的方法是,替换表名。

是,您不能这样使用它

替换此行:

pool.query('SELECT survey_n_1,lulc,gm FROM table',function(err,rows,fields) {
作者:


更好的方法是替换表名。

我的查询类似于“选择调查,lulc,gm from table where=%s”,当我处理此查询时,我会遇到更多错误,但此查询在flask python中工作我的查询类似于“选择调查,lulc,gm from table where=%s”,当我处理此查询时,我会遇到更多错误,但是这个查询在python中工作