-1

Notice: Undefined index: confirm in C:\xampp\htdocs\assurance\confirmation.php on line 98

$confirm = $_POST['confirm'];

<label> Retype Password </label>

            <input type="password" name="confirm" />
  • Read through [this question](https://stackoverflow.com/questions/4261133/php-notice-undefined-variable-and-notice-undefined-index) to understand how to check if a variable or array key is set before using it, as in `if (isset($_POST['confirm'])) $confirm = $_POST['confirm'];` – Michael Berkowski Feb 15 '14 at 20:24

4 Answers4

1

You're probably running the form-handling code unconditionally, whether a form submission actually occurred or not.

You need something like:

<?php

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
   if (isset($_POST['confirm'])) {
          ... a post occured, and the confirm field was submitted
   }
}

... show the form.
meda
  • 45,103
  • 14
  • 92
  • 122
Marc B
  • 356,200
  • 43
  • 426
  • 500
0

You're attempting to assign the variable $confirm the value of $_POST['confirm'] when it hasn't been set. Add a check to the code to avoid the error.

Change:

$confirm = $_POST['confirm'];

To:

$confirm = ( isset($_POST['confirm'] ) ) ? $_POST['confirm'] : '';
Nathan Dawson
  • 18,138
  • 3
  • 52
  • 58
0

did you submit the form?

by the way to espace the notice use

 if(isset($_POST["confirm"])
ponciste
  • 2,231
  • 14
  • 16
0

Please check first:

  • Do you have a <form>-Tag before your <input>?

    <form method="POST" action="path/to/file.php"><input name="confirm" type="password"> </form>

  • Do you have a button? If you have something like a login form, you need a button to "submit"
    <input type="submit">


Then write in your file:

if($_SERVER['REQUEST_METHOD'] == 'POST'){ if(isset($_POST['confirm']){
/* Do whatever you want */
}
}

a duck
  • 69
  • 6