Node.JS does not save the data of a form

0

Good afternoon everyone! I'm trying to save the data from a form, and I have no idea why it's not saving. I remember that I would have to use a stringify, or something like that, but I can not see it. Below are the view (ejs) and the index.js information! (I've hidden the host information and privacy connection.):

<div class="row">
<form class="col s12" action="/salvar" method="post">
    <div class="row">
        <div class="input-field col s12">
            <label for="cognition_name">Nome</label>
            <input id="cognition_name" type="text" class="validate">
        </div>
        <div class="input-field col s12">
            <label for="cognition_age">Data de Nascimento</label>
            <input id="cognition_age" type="text" class="validate">
        </div>
        <div class="input-field col s12">
            <a class="waves-effect waves-light btn" 
id="send_cognition_people">SEND</a>
        </div>
    </div>
</form>
</div>

const express = require('express')
const faker = require('faker')
const bodyParser = require('body-parser')
const expressLayouts = require('express-ejs-layouts')
const app = express()
const port = process.env.PORT || 5000
const mysql = require("mysql");
const fs = require("fs");
const connection = mysql.createConnection({host: "",user: "", 
password: "", database:""});

app.set('view engine', 'ejs');// Setamos que nossa engine será o ejs
app.use(expressLayouts);// Definimos que vamos utilizar o express-ejs-
layouts na nossa aplicação
app.use(bodyParser.urlencoded({ extended: true })); // Com essa 
configuração, vamos conseguir parsear o corpo das requisições
app.use(bodyParser.json());// tratamento do body para receber o json em caso 
de necessidade.
app.use(express.static(__dirname));
app.listen(port, () => {console.log('Servidor online em 
http://localhost:${port}')})


app.get('/cadastro', function (req, res) {
res.render('pages/cadastro');
})
app.post("/salvar", function (req, res) {
var cadastro = req.body;
console.log(cadastro);

connection.connect(function(err) {
if (err) throw err;
console.log("Connected!");
var qsql = "INSERT INTO COGNITION_PEOPLE (COGNITION_NAME,COGNITION_AGE, 
COGNITION_STATUS) VALUES ({$name},{$age}, 1)";
connection.query(qsql, function (err, result) {
if (err) throw err;
console.log("1 record inserted");
});
});
});
    
asked by anonymous 08.03.2018 / 20:06

0 answers