What's wrong in my code? It seems like it's not counting even if I try many attempts because I want to redirect the user to account registration page after 3 error attempts. But if I change the $atmp = 0; to $atmp = 3;, it redirects me to the registration page. My problem is that it is not counting the attempts.
<?php
$atmp = 0;
if (isset($_POST['login'])){
$user = $_POST['username'];
$pword = $_POST['password'];
include ("connection.php");
$atmp = $_POST['hidden'];
if($atmp<3){
$query = "SELECT fld_username, fld_password FROM tbl_account WHERE fld_username = '$user' AND fld_password = '$pword'";
$result = mysqli_query ($conn, $query);
if($query){
if (mysqli_num_rows($result)){
while (mysqli_fetch_array($result)) {
echo "<script> alert('You are logged in Successfully!'); window.location = 'profile.php'; </script>";
}
}
else{
$atmp++;
echo '<script> alert("You have invalid username/password and the number of attempt is '. $atmp .'");window.location = "index.php";</script>';
}
}
}
if ($atmp==3) {
echo '<script> alert("You have invalid username/password!");window.location = "accountregistration.php";</script>';
}
}
?>
This is the code for HTML
<!DOCTYPE html>
<html>
<head>
<title>LOGIN</title>
</head>
<body>
<form action="" method="POST">
<?php
echo "<input type = 'hidden' name = 'hidden' value = '".$atmp."'>";
?>
<fieldset>
<legend>Login</legend>
<label>Username:</label><input type="Text" name="username" id="username"><br><br>
<label>Password:</label><input type="password" name="password" id="password"><br><br>
               <input name="login" type="submit" value="Login">   <input name="clear" type="reset" value="Clear">
</fieldset>
</form>
</body>
</html>