注意:未定义变量:用户名、密码、dataAction


Notice: Undefined variable: username, password, dataAction

我尝试了几种不同的方法,并研究了几个类似的问题,希望能使我的页面正确处理。然而,我一直没有成功。我收到三个通知说未定义变量:

Notice: Undefined index: username
Notice: Undefined index: password
Notice: Undefined index: dataAction
$usernameLabel = "Username:";
$usernameName = "username";
$usernameValue = $_POST[$usernameName];
$passwordLabel = "Password:";
$passwordName = "password";
$passwordValue = $_POST[$passwordName];
$submitName = "dataAction";
$submitValue = "Submit";

您应该检查该值是否已设置

$usernameLabel = "Username:";
$usernameName = "username";
 //check if the $_POST array is populated and contain this key and there is a value associated to it
if(isset($_POST[$usernameName]))
{
   $usernameValue = $_POST[$usernameName];
}