2017-04-01 139 views
-1

我試圖運行下面的代碼... HTML ... signup.html始終顯示未定義指數 'confirmPassword'

<div> 
    <label for="create-password">Create Password</label> 
    <input id="create-password" type="password" placeholder="Atleast 6 characters" name="password" required> 
</div> 
<div> 
    <label for="confirm-password">Confirm Password</label> 
    <input id="confirm-password" type="password" placeholder="Atleast 6 characters" name="confirmPassword" required> 
</div> 

PHP部分

$password = $_POST['password']; 
$confirmPassword = $_POST['confirmPassword']; 
if($password != $confirmPassword) 
     echo "Passwords do not match"; 

每當我嘗試運行它說

注意:未定義的索引:E:\ xampp \ htdocs \ Nishat的Web Design \ signup_process.php中的confirmPassword行26 密碼不匹配

我不明白爲什麼它不考慮第二輸入名稱= confirmPassword ... 如果有人可以幫助那麼這將是appreciateable

+1

print_r($ _ POST),看看你在帖子中獲得的內容 –

回答

0

有沒有問題,你的代碼只是檢查您指定的形式方法的帖子我已經試過代碼和它的正常工作......,總是首先檢查輸入字段isset或不...這裏是我的代碼

<?php 
if(isset($_POST['submit'])) 
{ 
$password = $_POST['password']; 
$confirmPassword = $_POST['confirmPassword']; 

if($password != $confirmPassword) 
echo "Passwords do not match"; 
} 
?> 

HTML:

<html> 
<head> 
    <meta charset="utf-8"> 
    <title></title> 
</head> 
<body> 
<form method="post"> 
<div> 
        <label for="create-password">Create Password</label> 
        <input id="create-password" type="password" 
        placeholder="Atleast 6 characters" name="password" required> 
       </div> 
       <div> 
        <label for="confirm-password">Confirm Password</label> 
        <input id="confirm-password" type="password" 
        placeholder="Atleast 6 characters" name="confirmPassword" required> 
       </div> 
       <input type="submit" name="submit"> 
    </form> 
</body> 

如果您發現此解決方案的權利PLZ勾選這是一個正確的答案。

+0

我檢查了它的人......我的方法被設置爲發佈....我做了你在你的代碼中所做的事情......用我的代碼包圍了如果條件和提供了相同的其他部分......但仍然當我運行代碼的「其他」部分運行....有些形式的方法是錯誤的.... PLZ幫助 –

+0

有沒有在這段代碼中的其他部分我可以詳細瞭解你指的是哪一部分 –

+0

@NishatSayyed print $ _POST數組,所以你可以知道什麼值傳遞因爲我試過代碼,然後發佈它,並嘗試修剪密碼字段,如果有任何額外的空間留下....讓我知道什麼是輸出 –