Although I am aware of the potential risks involved in connecting to a database using JavaScript, for this particular project, I have made an exception. The purpose of this project is unique and requires the use of JavaScript.
document.getElementsByClassName("option")[0].onclick = function() {
event.preventDefault();
var mysql = require('mysql');
var con = mysql.createConnection({
host: "localhost",
user: "root",
password: "",
database: "dbname"
});
con.connect(function(err) {
if (err) throw err;
var email = document.getElementById("email").value;
var password = document.getElementById("password").value;
var sql = 'SELECT * FROM accounts WHERE email = ' + mysql.escape(email) + ' AND password = ' + mysql.escape(password);
con.query(sql, function (err, result) {
if (err) throw err;
console.log(result);
});
});
}
While I have previously worked on a similar project using PHP, I am now exploring the same with JavaScript. However, there seems to be an issue at hand. My intention is to display the result in the console but instead, I am encountering the following:
https://i.sstatic.net/wqdt1.png
I do not claim to be an expert programmer - in reality, this project serves as a learning experience for me as a student. Any assistance or guidance would be greatly appreciated!