Skip to content

Instantly share code, notes, and snippets.

@camarin24
Created October 10, 2016 15:15
Show Gist options
  • Save camarin24/654242af69cab1d00b6c08128ee3c9b8 to your computer and use it in GitHub Desktop.
Save camarin24/654242af69cab1d00b6c08128ee3c9b8 to your computer and use it in GitHub Desktop.
Insert whit Mysql DataBase and Node.js
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