I am trying to set some more rules for my login page, such as if the person has not activated his or her account, then I shouldn’t log him or her in… I am not sure why these codes here work but if I do it the other way, it doesn’t work… The following codes work
<?php
session_start();
if (!isset($_POST['submit'])) {
header("Location: ../index.php?=error");
exit();
} else {
include 'dbh.php';
$uid = mysqli_real_escape_string($conn, $_POST['uid']);
$pwd = mysqli_real_escape_string($conn, $_POST['password']);
// include error handlers:
// Check to see if the inputs are empty
//Check to see if user has activated his or her account before logging in
$sql = "SELECT user_activate FROM users ";
$result = mysqli_query($conn, $sql);
$resultCheck = mysqli_num_rows($result);
if ($resultCheck > 0) {
while ($row = mysqli_fetch_assoc($result)) {
if ($row['user_activate'] == 0) {
header("Location: ../index.php?=notactivated");
exit();
}
}
}
if(empty($uid) || empty($pwd)) {
header("Location: ../signup.php=?empty");
exit();
} else {
// Check to see if the username exists in the database
$sql = "SELECT * FROM users WHERE user_uid='$uid' OR user_email='$uid'";
$result = mysqli_query($conn, $sql);
$resultCheck = mysqli_num_rows($result);
if ($resultCheck < 1) {
header("Location: ../index.php?login=error");
exit();
} else {
// Does the password match the password in the database?
if ($row = mysqli_fetch_assoc($result)) { // insert database results into an array
// De-hasing the password
$hashedPwdCheck = password_verify($pwd, $row['user_password']);
if ($hashedPwdCheck == false) {
header("Location: ../signup.php=?empty");
exit();
} elseif ($hashedPwdCheck == true) {
// Log in the user here
$_SESSION['u_id'] = $row['user_id'];
$_SESSION['u_first'] = $row['user_first'];
$_SESSION['u_last'] = $row['user_last'];
$_SESSION['u_email'] = $row['user_email'];
$_SESSION['u_uid'] = $row['user_uid'];
header("Location: ../index.php?login=success");
exit();
}
}
}
}
}
But if I were to just update these lines only:
$sql = "SELECT * FROM users WHERE user_uid='$uid' OR user_email='$uid' AND email_activate='0'";
Then it doesn’t work…