Created
October 10, 2016 15:15
-
-
Save camarin24/654242af69cab1d00b6c08128ee3c9b8 to your computer and use it in GitHub Desktop.
Insert whit Mysql DataBase and Node.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.post("/registro", function (req, res) { | |
var datos = { | |
nombre: req.body.nombre, | |
apellido: req.body.apellido, | |
fecha_nacimiento: req.body.fechaNacimiento, | |
correo_electronico: req.body.email, | |
contrasenia: req.body.password | |
}; | |
db.query("SELECT * FROM personas WHERE correo_electronico = ?", [req.body.email], function (err, user) { | |
if (err) throw err; | |
if (user.length > 0) { | |
//@params | |
//noRegistro : is a locals variable | |
res.render("registro", { noRegistro: "Ya existe una persona con el mismo correo electónico" }); | |
} else { | |
db.query('INSERT INTO personas SET ?', datos, function (err, rows) { | |
if (err) throw err; | |
console.log('Last insert ID:', rows.insertId); | |
}); | |
} | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment