2015-02-24 120 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"]; 

注意名稱屬性。