0
<?php
    if(isset($_POST["reset-password"])) {
        $conn = mysqli_connect("localhost", "root", "", "borgos");
        $FName = $_POST['FName'];
        $sql = "UPDATE user_account SET UserPassword = '" . md5($_POST["UserPassword"]). "' WHERE FName = $FName";
        $result = mysqli_query($conn,$sql);
        $success_message = "Password is reset successfully.";

    }
?>

Undefined index: FName in C:\xampp\htdocs\resetpassword.php on line 4

I don't know what's the problem here, FName is in my database.

arghtype
  • 4,376
  • 11
  • 45
  • 60
J. RoeWa
  • 23
  • 8
  • what data is send there? add this: print_r($_POST) – Marcin Apr 16 '17 at 19:34
  • 1
    Your script is at risks, you should **really** consider using [PPS : Prepared Parameterized Statements](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php). This will help [Preventing SQL injection](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php). Please use `error_reporting(E_ALL); ini_set('display_errors', 1);` on top of your pages to enable errors showing up. Last but not least, you should **not** use MD5 anymore, but `password_hash / password_verify` [LINK](http://php.net/manual/fr/function.password-hash.php) – OldPadawan Apr 16 '17 at 19:35
  • 1
    FName is in your database, yes, but is it in the sent $_POST-data? – junkfoodjunkie Apr 16 '17 at 19:41
  • Add html FORM to question – My Name Apr 16 '17 at 19:45
  • @OldPadawan Okay I will keep that in mind :) thanks for telling me that I appreciate it – J. RoeWa Apr 16 '17 at 20:08
  • Possible duplicate of [PHP: "Notice: Undefined variable", "Notice: Undefined index", and "Notice: Undefined offset"](http://stackoverflow.com/questions/4261133/php-notice-undefined-variable-notice-undefined-index-and-notice-undef) – showdev Apr 20 '17 at 16:29

1 Answers1

0

Because $_POST['FName']; not posted

Solution :

$FName = '';
if($_POST['FName']){
      $FName = $_POST['FName'];
}
My Name
  • 285
  • 1
  • 4
  • 18
  • So, just ignore the error? You'd be better off generating an error if the field is missing. (Or figuring out _why_ it's missing.) –  Apr 18 '17 at 00:34
  • @duskwuff in question say Undefined index, this error only for variable is not exists. – My Name Apr 18 '17 at 06:39