Answer the question
In order to leave comments, you need to log in
Why does every query to the database cause the same error?
Good morning, please tell me why these characters appear in my line: \
I already tried replace, and splice doesn’t help, they don’t seem to exist, but they are there when it displays an error, I killed the night in search of a solution. Please help .
app.post('/register-step2', (req,res,next) => {
let email = req.body.email;
let role = req.body.role;
let firstname = req.body.firstname;
let password = req.body.password;
let select = "SELECT * FROM users WHERE email = '" + email + "'";
let insert = "INSERT INTO users (firstname,email,password,role) VALUES('" + firstname + "','" + email + "','" + hash + "','" + role + "')"
connection.query(select, (err,res) => {
if (res.length < 1) {
bcrypt.genSalt(saltRounds, (err, salt) => {
bcrypt.hash(password, salt, (err, hash) => {
connection.query(insert, (err,res) => {
if(err) console.log(err);
else {
console.log(email)
}
});
});
});
}
else {
return console.log('user registered!');
}
});
return res.redirect('/step2')
});
code: 'ER_PARSE_ERROR',
errno: 1064,
sqlMessage:
'You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near \'\'Text)\' at line 1',
sqlState: '42000',
index: 0,
sql:
'INSERT INTO users (firstname,email,password,role) VALUES(\'History\',\'[email protected]\',\'$2b$10$0bfFB/gNQaMIDPKc34zq.em3/DRAgrHiO5YpkizNA7gfqt1ZkQcHW\',\'Text)' }
Answer the question
In order to leave comments, you need to log in
let select = `SELECT * FROM users WHERE email = '${email}'`;
let insert = `INSERT INTO users (firstname, email, hash, role) VALUES('${firstname}' ,'${email}', '${password}', '${role}')`
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question