2015-02-24 119 views
0

第一行出错未定义索引:$ pwd 还有未定义的变量在它下面。 请显示新的代码谢谢! 它的结尾吐出来。PHP未定义索引/变量

$pwd = $_POST['$pwd'];    //Error undefined index: $pwd 

if(strlen($pwd) < 8) { 
     $error .= "Password too short! 
"; 
}          //This line undefined variable 

获取上述错误在这里******错误变量

if(strlen($pwd) > 20) { 
     $error .= "Password too long! 
"; 
} 

if(strlen($pwd) < 8) { 
     $error .= "Password too short! 
"; 
} 

if(!preg_match("#[0-9]+#", $pwd)) { 
     $error .= "Password must include at least one number! 
"; 
} 


if(!preg_match("#[a-z]+#", $pwd)) { 
     $error .= "Password must include at least one letter! 
"; 
} 


if(!preg_match("#[A-Z]+#", $pwd)) { 
     $error .= "Password must include at least one CAPS! 
"; 
} 



if(!preg_match("#\W+#", $pwd)) { 
     $error .= "Password must include at least one symbol! 
"; 
} 


if($error){ 
     echo "Password validation failure(your choice is weak): $error"; 
} else { 
     echo "Your password is strong."; 
} 

再次感谢:d

+2

你真的有一个名称为“$ pwd”,美元符号和全部的元素吗? – adeneo 2015-02-24 10:59:26

+3

也许'$ pwd = $ _POST ['pwd'];'? – lmarcelocc 2015-02-24 11:00:03

+0

(与问题无关:)此外,您可能会考虑在字符串的末尾使用“\ n”(添加换行符),而不是真正以换行符结尾。 – matthias 2015-02-24 11:39:56

回答

0

代替$pwd = $_POST['$pwd'];使用$pwd = $_POST['pwd'];

+0

仍然收到相同的索引错误和未定义的变量。 – 2015-02-24 11:06:58

+1

那么也许你的密码输入名称不是'密码'?检查$ _POST数组中的内容 - print_r($ _ POST); - 该数组中的一个键将是您的输入密码名称。 – 2015-02-24 11:08:43

0

$ PWD = $ _ POST [” $ PWD'];

我想这意味着是:

$ PWD = $ _POST [ 'PWD'];

但它取决于密码字段在您的窗体中具有的名称。如果窗体上的密码字段的名称是密码,然后使它$ _ POST [“密码”]

0

,如果你有...

<input type="password" name="pwd"> 

然后在你的PHP脚本,你应该叫它

$pwd = $_POST["pwd"]; 

注意名称属性。