我想擁有可以啓用或禁用的用戶帳戶。如何禁用用戶帳戶php/mysql
我在我的表中設置爲yes或no的活動字段。
這是我的登錄頁面的代碼。
<?php
/* User login process, checks if user exists and password is correct */
require_once 'includes/db.php';
// Escape email to protect against SQL injections
$email = $mysqli->escape_string($_POST['email']);
$result = $mysqli->query("SELECT * FROM dxd_membership WHERE email='$email'");
if ($result->num_rows == 0){ // User doesn't exist
$_SESSION['message'] = "User with that email doesn't exist!";
header("location: error.php");
}
else { // User exists
$user = $result->fetch_assoc();
$active = $mysqli->query("SELECT * FROM dxd_membership WHERE email = '$email' AND active = 'YES'");
if ($active == '1')
{
if (password_verify($_POST['password'], $user['password'])) {
$userid = $_SESSION['userid'];
$_SESSION['email'] = $user['email'];
$_SESSION['firstname'] = $user['firstname'];
$_SESSION['lastname'] = $user['lastname'];
$_SESSION['username'] = $user['username'];
$_SESSION['paynum'] = $user['paynum'];
$_SESSION['empnum'] = $user['empnum'];
$_SESSION['phone'] = $user['phone'];
$_SESSION['active'] = $user['active'];
$_SESSION['lastlogin'] = $user['lastlogin'];
$_SESSION['signup'] = $user['signup'];
$_SESSION['lastupdate'] = $user['lastupdate'];
// This is how we'll know the user is logged in
$_SESSION['logged_in'] = true;
$update = $mysqli->query("UPDATE dxd_membership SET lastlogin=NOW() WHERE email = '$email'");
header("location: welcome.php");
}
else {
$_SESSION['message'] = "You have entered wrong password please try again!";
header("location: error.php");
}
}
else {
header("location: disabled.php");
}
}
?>
我相信這是一個愚蠢的錯誤,我這裏有,但它不會檢查活動字段,然後要麼讓用戶登錄到頁面的welcome.php如果活躍是肯定的或發送給殘疾人。如果他們的帳戶活動被設置爲no(禁用),則爲php頁面。
任何人都可以幫助我糾正代碼,使其工作。
感謝
爲什麼'$ active =='1'',如果你得到一個回報,你知道活動是1. – chris85