一段代码
$LoginRS__query=sprintf("SELECT user_handle, user_password FROM users_entity WHERE user_handle=%s AND user_password=%s AND activation_status='Active'",
GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text"));
$LoginRS = mysql_query($LoginRS__query, $f12_database_connect) or die(mysql_error());
$loginFoundUser = mysql_num_rows($LoginRS);
if ($loginFoundUser) {
$loginStrGroup = "";
//declare two session variables and assign them
$_SESSION['MM_Username'] = $loginUsername;
$_SESSION['logged_in']="True";
$_SESSION['MM_UserGroup'] = $loginStrGroup;
if (isset($_SESSION['PrevUrl']) && true) {
$MM_redirectLoginSuccess = $_SESSION['PrevUrl'];
}
header("Location: " . $MM_redirectLoginSuccess );
}
else {
header("Location: ". $MM_redirectLoginFailed );
}
}
数据库查询activation_status="Active"
的用户。该字段具有"Pending"
或"Active"
这两个值中的任何一个。如果状态为"Pending"
,我想发送到另一个页面。该页面适用于尚未激活其帐户的用户。如何获取结果并将其分配给变量?或者有更好的方法吗?
答案 0 :(得分:0)
只需选择数据而不参考activation_status,并使用if语句进行检查。
编辑:
您可能正在寻找的代码:
$LoginRS__query=sprintf("SELECT user_handle, user_password, activation_status FROM users_entity WHERE user_handle=%s AND user_password=%s",
GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text"));
$LoginRS = mysql_query($LoginRS__query, $f12_database_connect) or die(mysql_error());
$loginFoundUser = mysql_num_rows($LoginRS);
if ($loginFoundUser) {
// Make sure user is activated.
$row = mysql_fetch_Array($LoginRS);
if ($row['activation_status'] === 'Pending') {
header("Location: some-other-page");
}
$loginStrGroup = "";
//declare two session variables and assign them
$_SESSION['MM_Username'] = $loginUsername;
$_SESSION['logged_in']="True";
$_SESSION['MM_UserGroup'] = $loginStrGroup;
if (isset($_SESSION['PrevUrl']) && true) {
$MM_redirectLoginSuccess = $_SESSION['PrevUrl'];
}
header("Location: " . $MM_redirectLoginSuccess );
}
else {
header("Location: ". $MM_redirectLoginFailed );
}
}
答案 1 :(得分:-1)
这是解决方案,正确编码 ......
<?php
$LoginRS_StrQuery = 'SELECT user_handle, user_password, activation_status FROM users_entity '.
"WHERE user_handle=%s AND user_password=%s LIMIT 0,1";
$LoginRS__query = sprintf($LoginRS_StrQuery, GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text"));
$LoginRS = mysql_query($LoginRS__query, $f12_database_connect);
if(is_resource($LoginRS) && mysql_num_rows($LoginRS) > 0){
$loginStrGroup = '';
//declare two session variables and assign them
$_SESSION['MM_Username'] = $loginUsername;
$_SESSION['logged_in'] = 'True';
$_SESSION['MM_UserGroup'] = $loginStrGroup;
$LoggedUser = mysql_fetch_assoc($LoginRS);
if($LoggedUser['activation_status'] === 'Pending'){
// redirect him/her to wherever you want
} elseif(isset($_SESSION['PrevUrl']) && true){
$MM_redirectLoginSuccess = $_SESSION['PrevUrl'];
exit;
} else{
header("Location: " . $MM_redirectLoginSuccess );
exit;
}
} else{
header("Location: ". $MM_redirectLoginFailed );
exit;
}
?>