I am trying to make a log in system. Right now I am working on allowing the user to register. I am trying to make it so you can’t create an account that has the same username or email as another. However, it is giving me a parse error.
Here is the code:
app.post("/create", (req, res) => {
const email = req.body.email;
const username = req.body.username;
const password = req.body.password;
db.query("SELECT email, username FROM users WHERE email = ? AND username = ?"),
[email, username],
(err, result) => {
if (err) {
console.log(err);
} else if (result) {
res.send("Username or Email is already in use.")
} else {
db.query(
"INSERT INTO users (email, username, password) VALUES (?,?,?)",
[email, username, password],
(err, result) => {
if (err) {
console.log(err);
} else {
res.send("Values Inserted");
}
}
);
}
};
});
Here is the error I am getting:
{
code: 'ER_PARSE_ERROR',
errno: 1064,
sqlMessage: "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '? AND username = ?' at line 1",
sqlState: '42000',
index: 0,
sql: 'SELECT email, username FROM users WHERE email = ? AND username = ?'
}