I am trying to create a login system using php. What I am trying to create is to have a page that ask for username, password, email. Then when the user fill in the fields to go to the next page where the user will be asked to put his username and password in order to login to the system. Moreover, I have created something but is not working properly. The form is submitted correctly and I receive the data into my database but when the user tries to login into the system it will only allow the LAST user that registered, to login with his credentials into the system. For all the other users that are registered also, the login is not working. Please can someone help to solve this issue?
Thanks.
My HTML and PHP Code:
<div class="container">
<div class="row">
<div class="col-xs-12">
<h2>Please sign in with your username<br>
and password to complete the form... Thanks!!!</h2>
<form method="post" action="success.php">
<?php
if(isset($_POST['login'])) {
$username = $_POST['user_username'];
$password = $_POST['user_password'];
$query = "SELECT * FROM users_info";
$result = mysqli_query($connection, $query);
while($row = mysqli_fetch_assoc($result)) {
$db_username = $row['user_username'];
$db_password = $row['user_password'];
}
if($username !== $db_username) {
echo "Username does not exist";
}else if ($password !== $db_password) {
echo "Password does not exist";
}else {
header("Location: form.php");
}
}
?>
<div class="form-group">
<label for="user_username">Enter Username</label>
<input type="text" name="user_username" class="form-control" required>
</div>
<div class="form-group">
<label for="user_username">Enter Password</label>
<input type="password" name="user_password" class="form-control" required>
</div>
<div class="form-group">
<input type="submit" name="login" value="Log In" class="btn btn-success">
</div>
</form>
</div>
</div>
</div>