Skip to content

Commit

Permalink
Update index.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Luis-60 authored Oct 25, 2023
1 parent 1536b01 commit 13d30d4
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,35 @@ const db = require("./db.js");
const port = process.env.PORT || 3000;

const express = require("express");
const bodyParser = require("body-parser");

const app = express();

app.get("/", function(req, res){
res.sendFile(__dirname + "/form.html")

});
app.use(express.urlencoded({ extended: true }));
app.use(express.json());

app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json())

app.post("/enviar-dados", async (req, res) => {
res.send("Nome: " ) + req.body.nome +
"<br>Email: " + req.body.email + "</br>" +
"<br>Telefone: " + req.body.telefone + "</br>" +
"<br>cpf: " + req.body.cpf + "</br>" +
"<br>Sexo: " + req.body.genero + "</br>" +
"<br>DataDeNascimento: " + req.body.data_nascimento + "</br>" +
"<br>Cidade: " + req.body.cidade + "</br>" +
"<br>Estado: " + req.body.estado + "</br>" +
"<br>Endereço: " + req.body.endereco + "</br>"
});
app.post('/submit', (req, res) => {
const {nome, email, telefone, cpf, data_nascimento,
cidade, estado} = req.body;

db.pool.query(
'INSERT INTO formulario (nome, email, telefone, cpf, datanascimento, cidade, estado) VALUES ($1, $2, $3, $4, $5, $6, $7)',
[nome, email, telefone, cpf, data_nascimento,
cidade, estado],
(err, result) => {
if (err) {
console.error(err);
res.send('Erro ao inserir os dados no banco de dados.' + err.message);
} else {
res.sendFile(__dirname + "/di.html");
}
}
);
});


app.listen(port, () => {
console.log('Servidor rodando na porta ${port}');
Expand Down

0 comments on commit 13d30d4

Please sign in to comment.