I have a little problem, because when I am trying to login on my page i gets two errors: one of them that's undefined password ( I checked the html form and other sources where problem can appear but didn't find anything.) The second one it's "Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]:
<!DOCTYPE html>
<html>
<head>
<title> Strona o nalewkach </title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">
<link rel="stylesheet" href="https://pro.fontawesome.com/releases/v5.10.0/css/all.css" integrity="sha384-AYmEC3Yw5cVb3ZcuHtOA93w35dYTsvhLPVnYs9eStHfGJvOvKxVfELGroGkvsg+p" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div class="container h-100">
<div class="d-flex justify-content-center h-100">
<div class="user_card">
<div class="d-flex justify-content-center">
<div class="brand_logo_container">
<img src= "img/logo.png" class="brand_logo" alt="Nalewki">
</div>
</div>
<div class="d-flex justify-content-center form_container">
<form>
<div class="input-group mb-3">
<div class="input-group-append">
<span class="input-group-text"><i class="fas fa-user"></i></span>
</div>
<input type="text" name="username" id="username" class="form-control input_user" required>
</div>
<div class="input-group mb-2">
<div class="input-group-append">
<span class="input-group-text"><i class="fas fa-key"></i></span>
</div>
<input type="password" name="password" id="password" class="form-control input_pass" required>
</div>
<div class="form-group">
<div class="custom-control custom-checkbox">
<input type="checkbox" name="rememberme" class="custom-control-input" id="customControlInLine">
<label class="custom-control-label" for="customControlInLine">Zapamiętaj mnie</label>
</div>
</div>
</div>
<div class="d-flex justify-content-center mt-3 login-container">
</div>
</form>
<div class="mt-4">
<div class="d-flex justify-content-center links">
Nie posiadasz konta? <a href="#" class="ml-2">Zarejestruj sie</a>
<script>
$(function(){
$('#login').click(function(e){
var valid = this.form.checkValidity();
if(valid){
var username = $('#username').val();
var password = $('password').val();
}
e.preventDefault();
$.ajax({
type: 'POST',
url: 'jslogin.php',
data: {username: username, password: password},
success: function(data){
alert(data);
if ($.trim(data)==="1"){
setTimeout(' window.location.href = "index.php"',2000);
}
},
error: function(data){
alert('wystapil blad');
}
});
});
});
</script>
</body>
</html>
jslogin.php:
<?php
require_once('config.php');
$username = $_POST['username'];
$password = $_POST['password'];
$sql = "SELECT * FROM useraccounts.users where username = ? AND password = ? LIMIT=1 ";
$stmtselect = $db->prepare($sql);
$result = $stmtselect->execute([$username,$password]);
if($result){
$user=$stmtselect->fetch(PDO::FETCH_ASSOC);
if($stmtselect->rowCount() > 0){
echo '1';
}else{
echo'Nie znaleziono uzytkownika';
}
}else{
echo'Wystapily bledy przy laczeniu z baza danych';
}
?>