I am trying to validate input login via javascript by passing PHP variables. I cannot execute it properly for some reason. I'd appreciate your comments. Here's the code:
PHP:
$personal = mysqli_query($connect,"SELECT * FROM basic ORDER BY user_id DESC ");
while($row = mysqli_fetch_array($personal)){
$user = $row['username'];
$user_password = $row['password'];
}
Javascript / jQuery:
function enter_log() {
var login_username = $("#username_field_log");
var pass_password = $("#pass_field_log");
var button = $("#enter_field_log");
var php = "<?= echo $user; ?>";
if ((login_username.val() == "") || (pass_password.val() == "")) {
$("#user_log_info").fadeIn('slow');
$("#user_log_info").text("Not a proper login input");
login_username.addClass("error");
pass_password.addClass("error");
return false;
}
else if ((login_username.val() != php ) || (pass_password.val() == "")) {
$("#user_log_info").fadeIn('slow');
$("#user_log_info").text("Not a proper login input");
login_username.addClass("error");
pass_password.addClass("error");
return false;
}
}
So in other words - the code should return false ( and it does so ) when the fields are empty but it doesn't return TRUE when the input is correct ( I mean when the username is correct ) so I assume the PHP variable $user
is not passed by correctly to javascript?