Hey I've seen all the solutions here on StackOverflow on the topic but they seem to not work, I don't know why. I've this code inside the $(form).submit(function(e){...});
event handler.
e.preventDefault();
let formData = new FormData();
formData.append('username', username.value);
formData.append('password', password.value);
$.ajax({
url: 'login.php',
type: 'POST',
data: formData,
processData: false,
contentType: false,
success: function(response) {
console.log(response);
},
error: function() {
console.log('fail');
}
})
By the look of things, I think the login.php is receiving the formData value because when I submit the form nothing happens.
This is the login.php
<?php
session_start();
$password = $username = '';
$_SESSION['user'] = '';
if($_SERVER['REQUEST_METHOD'] == 'POST') {
if(isset($_POST['login'])) {
include_once('db.php');
$username = strip_tags($_POST['username']);
$passd = strip_tags($_POST['password']);
$passd = md5($password);
$sql = "select * from users where username = '" . $username . "' limit 1";
$query = mysql_query($sql);
if($query) {
$row = mysql_fetch_assoc($query);
$dbpass = $row['password'];
if($password == $dbpass) {;
$_SESSION['user'] = $username;
header('Location: admin.php');
} else {
echo 'Wrong username or password!';
}
} else {
echo mysql_error();
}
}
}
?>
How do I make this work? Thank you in advance.
</div>