Thanks everybody I've solved this problem days ago.But I've edited to delete some specific info in the question(code). So it is not duplicate just revised for protection. I am using nodejs on backend, html on front-end and a database(mysql) to build a web page. And i need a login page for that. My html and nodejs codes are below. There is nothing wrong until the validate() function. My html page should use it, but it doesn't. Nothing changes on html side. Where is my mistake?
NODEJS CODE:
var mysql = require('mysql');
var express = require('express');
var http = require('http');
var login = express();
//mysql bağlantısı
var db = mysql.createConnection({
.................});
//connection
db.connect((err) => {
if(err){
throw err;}
else console.log("connected");
});
//veritabanından bilgi çekimi
login.get('/', (req,res) => {
let sql = 'SELECT `user_name`, `pass` FROM `users`';
db.query(sql,(err,result) => {
if(err) throw err;
console.log(result);
res.sendFile(__dirname + "/login.html");
var .... = result[0].......; //set user name
console.log(.);...
var ......= result[0]......; //set user pass
console.log(.....);
});
});
function validate(){
var username = document.getElementById("....").value;
var password = document.getElementById("....").value;
var err=document.getElementById("error").innerHTML;
//giriş alanları boş kalırsa
if(username==""){
alert("Bu gerekli bir alandır");}
if(password==""){
alert("Bu gerekli bir alandır");}
//username şifre eşleşmesi
if ( ....== "....." && .....== "...."){
document.getElementById("error").innerHTML="Log in sucessfull";
window.location = "login.html";
return false;
}
}
HTML CODE
form id="form_id" action= "/" method="post" name="myform"
input type="text" id="...." placeholder="......" required
input type="....." id="....." placeholder="Password" required
input type="button" id="submit" value="LOGIN" onclick="validate()"
script src="path"