如果用户没有输入用户名,但是当用户输入显示"username": null
的用户名时,我会显示错误消息。当没有我试图在数组中添加if语句时,我怎么也不能显示任何错误
$username = $_POST['username'];
if(empty($username)){
$username_error = "Please enter a Username";
}
$json = array(
'ErrorMsg' => array(
'username' => $username_error,
),
'booleanFlag' => TRUE,
);
答案 0 :(得分:0)
您需要为$ username_error提供备用值(空白):
$username = $_POST['username'];
if(empty($username)){
$username_error = "Please enter a Username";
} else {
$username_error = "";
}
$json = array(
'ErrorMsg' => array(
'username' => $username_error,
),
'booleanFlag' => TRUE,
);