在你说它之前已经回答之前,我已经尝试了一切,从字面上看。
我正在尝试使用两个 WHERE 子句计算 mysqli 查询中的行数。
if (isset($_POST['member_name']) and isset($_POST['memeber_password'])) {
$member_name_input = mysqli_real_escape_string($query, $_POST['member_name']);
$member_password_input = mysqli_real_escape_string($query, $_POST['member_password']);
$result = mysqli_query($query, "SELECT count(*) AS member_count FROM `members` WHERE `member_name` = '$member_name_input' AND `member_password` = '$member_password_input'") or die(mysqli_error($query));
$counter = $row['member_count'];
if ($counter = 1) {
$result = mysqli_query($query, "SELECT * FROM `members` WHERE `member_name`='$member_name_input' AND `member_password`='$member_password_input'") or die(mysqli_error($query));
$row = mysqli_fetch_array($result);
$member_suspended = $row['member_suspended'];
$member_validation = $row['member_validation'];
}
if ($member_suspended < time() and $member_validation = 2) {
$_SESSION['member_id'] = $row['member_id'];
echo $counter;
} elseif ($member_suspended >= time()) {
$suspension_date = date('d. m. y.', $member_suspended);
echo '<div class="left_container"><h3>You are suspended until '.$suspension_date.'.</h3></div>';
} elseif ($member_validation = 1) {
echo '<div class="left_container"><h3>Your account has not been confirmed, yet.</h3></div>';
} else {
echo '<div class="left_container"><h3>Login unsuccessful.</h3></div>';
}
}
我的问题是,当我尝试使用无效的密码和/或用户名(该组合在表中不存在)登录时,$counter 仍然是 1,它满足第一个 if 语句的要求。
我尝试过以多种方式计算行数,但都没有奏效。
其他一些尝试是:
$counter = 0;
while ($row = mysqli_fetch_array($result)) {
++$counter;
}
和
$counter = mysqli_num_rows($result);
我只是想想办法让我的用户成功登录,并向无效的登录尝试显示错误消息。
感谢您抽出宝贵时间阅读本文并尝试提供帮助。:)