My Code:
function checkLogIn() {
var emailValue = document.getElementById("emails").value;
var usernameValue = document.getElementById("username").value;
var passwordValue = document.getElementById("password").value;
knex("users").select("id").where({
email: emailValue,
username: usernameValue,
password: passwordValue,
});
}
It should takes values from HTML and compare HTML values with MySQL DB values.
I know that the code is not properly correct but since I didn’t find anything about it, I was trying to test it a little bit. Does someone have any answer?
2
Answers
The
knex
function will return a promise and when that promise is fulfilled, either an empty array or an array of length 1.To check if a user exists with the email, username, and password value they entered, try:
I thought I would chime in with a modern version of an answer that doesn’t leak out variables anywhere and utilizes the best of Knex 🙂
See the comments explaining the nuances of the code.