4
Hello, I’m starting with Node.js
and MySQL
, and I have some problems at the moment. Well, I have a table called users, and I need to request data for verification, for example: My site has a registration form, but you need to check the data to see if there is a user already registered with the same data.
My code is like this so far:
var pool = mysql.createPool({
host : 'localhost',
user : 'root',
password : '',
database:'tabela'
});
pool.getConnection(function(err, connection) {
// Use the connection
var email = emailCadastro;
connection.query( 'SELECT * FROM usuarios WHERE email = ?',[email], function(err, rows) {
// And done with the connection.
connection.release();
// Don't use the connection here, it has been returned to the pool.
console.log(rows[0].email);
});
});
Please correct me if this code is wrong. The variable emailCadastro
comes from the user’s form.
The interpreter returns the following error:
Cannot read property 'email' of undefined
I wonder what the mistake is here and if anyone could help me.
Your database is actually called "table"?
– bfavaretto
No. Why? It doesn’t affect the right question?
– Perry the platypus
It depends, if the problem is a basis that doesn’t exist, it affects.
– bfavaretto
Well the table exists
– Perry the platypus