When I attempt login using the data from MyPHPAdmin the login does work, but the output gives me "You are logged out!" instead of the intended output "You are logged in!"
Note I have not worked on my logged-out script yet so that is missing.
My PHP code to check if a valid user logged in.
if (isset($_POST['login-submit'])){
require 'dbh.inc.php';
$mailuid = $_POST['mailuid'];
$password = $_POST['pwd'];
if (empty($mailuid) || empty($password)){
header("Location: ../PresenceLogin.php?error=emptyfields");
exit();
}
else {
$sql = "SELECT * FROM users WHERE uidUsers=? OR emailUsers=?;";
$stmt = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($stmt, $sql)) {
header("Location: ../PresenceLogin.php?error=sqlerror");
exit();
}
else {
mysqli_stmt_bind_param($stmt, "ss", $mailuid, $mailuid);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
if ($row = mysqli_fetch_assoc($result)) {
$pwdCheck = password_verify($password, $row['pwdUsers']);
if ($pwdCheck == false) {
header("Location: ../PresenceLogin.php?error=wrongpwd");
exit();
}
else if ($pwdCheck == true) {
session_start();
$_SESSION['userId'] = $row['idUsers'];
$_SESSION['userUid'] = $row['uidUsers'];
header("Location: ../Logged.php");
exit();
}
else {
header("Location: ../PresenceLogin.php?error=wrongpwd");
exit();
}
}
else {
header("Location: ../PresenceLogin.php?error=nouser");
exit();
}
}
}
}
else {
header("Location: ../PresenceLogin.php");
}
my PHP code for output if a registered user logged in
<?php
require "PresenceNavbar.php"
?>
<link href="css/Logged.css" rel="stylesheet" type="text/css">
<main>
<div>
<section class="Logging" id="Logging">
<?php
if (isset($_SESSION['userId']))
{
echo '<h1 class ="Logged">You are logged in!</h1>';
}
else
{
echo '<h1 class ="Logged">You are logged out!</h1>';
}
?>
</section>
</div>
</main>
<?php
require "footer.php";
?>