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

时间:2013-01-11 17:35:25

标签: php indexing undefined

我尝试了几种不同的方法并查看了几个类似的问题,希望能让我的页面正确处理。但是,我没有成功。我收到三条注意到Undefined变量的注意事项:

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";

1 个答案:

答案 0 :(得分:2)

您应该检查值是否已设置

$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];
}