I am trying to get the username from the database and verify it to the input value when submiting on button click, I have created this function but it is not working
function validate() {
var attempt = 3;
var mysql = require('mysql');
var con = mysql.createConnection({
host: "localhost",
user: "root",
password: "root",
database: "omega"
});
var username = document.getElementById("username").value;
var password = document.getElementById("password").value;
con.connect(function(err) {
if (err) throw err;
con.query("SELECT * FROM customers", function(err, result, fields) {
if (err) throw err;
if (username == result[0].user && password == "root") {
alert("Login successfully");
window.location.href = '/admin'; // Redirecting to other page.
return false;
} else {
attempt--; // Decrementing by one.
if (attempt > 0) {
alert("Vous avez " + attempt + " autres tentatives;");
}
// Disabling fields after 3 attempts.
if (attempt == 0) {
document.getElementById("username").disabled = true;
document.getElementById("password").disabled = true;
document.getElementById("submit").disabled = true;
return false;
}
}
});
});
}
and I did this on my button in twig code
<a class="login100-form-btn" onclick="validate()">Login</a>