Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/271.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在if-else条件下显示echo-define_Php - Fatal编程技术网

Php 在if-else条件下显示echo-define

Php 在if-else条件下显示echo-define,php,Php,我试图在代码中插入一个常量define,这样,如果有$error[],就可以插入对应define的字符串。就我而言: if($user->login($username,$password)){ header('Location: memberpage.php'); $_SESSION['user_name'] = $username; exit; } else { $error[] = 'Wrong username or password or yo

我试图在代码中插入一个常量define,这样,如果有$error[],就可以插入对应define的字符串。就我而言:

if($user->login($username,$password)){ 

    header('Location: memberpage.php');
    $_SESSION['user_name'] = $username;
    exit;
} else {
    $error[] = 'Wrong username or password or your account has not been activated.';

}
定义常数

define ('ERROR_LOGIN', 'Wrong username or password or your account has not been activated.');
如何在$ERROR[]之后插入ERROR\u LOGIN,以便在条件为false时返回其余部分


感谢您的帮助

您将常数存储到数组中,如下所示:

$error[] = ERROR_LOGIN;

@akmed在你的问题中,你提到了
INDEX\u ERROR
,你到底叫什么?我会更简单地解释,我需要替换-错误的用户名或密码,或者你的帐户尚未激活。-代码的第一部分带有常量define…
在$ERROR[]之后插入ERROR\u LOGIN如果条件为假,那么我将返回其余部分?
请自己阅读,目前还不清楚all@akmed它不起作用了?这是一个完全不同的错误消息。您尚未在用户类中创建
login()
方法。@ᵈˑ我不认为这一点会出现在
:(
并且在设置会话之前重定向不是一个好主意