0

I am trying to run the below code... HTML...signup.html

<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 Part

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

Whenever i try to run this it says

Notice: Undefined index: confirmPassword in E:\xampp\htdocs\Nishat's Web Design\signup_process.php on line 26 Passwords do not match

I dont understand why it is not considering the second input name = confirmPassword... If someone helps then it would be appreciateable

dparoli
  • 8,891
  • 1
  • 30
  • 38
Nishat Sayyed
  • 151
  • 2
  • 10

1 Answers1

0

There's no problem in your code. Just check that you specified form method to post I've tried code and it's working fine, and always first check input field isset or not. Here's my code

<?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>
</html>
Pang
  • 9,564
  • 146
  • 81
  • 122
  • I checked it man...my method is set to post....I did what you did in your code....surrounded my code with the if condition and provided an else part for the same......but still when i run the code the "else" part runs....something is wrong with the form method ....plz help – Nishat Sayyed Apr 01 '17 at 11:28
  • there's no else part in this code can i know in detail which part you are referring to – visana niraj Apr 01 '17 at 13:48
  • @NishatSayyed print $_POST array so you can know what values are passing cuz i tried code and then post it and also try trimming password field if there are any extra space left....let me know ok what are outputs – visana niraj Apr 01 '17 at 13:56