title: Get error when trying to send new password to e-mail by php
body: <p>I'm a beginner of <code>php</code> and now getting stuck on sending a new password to user e-mail if user requested in <code>android</code>.</p>
  
  <p><strong>ForgetPassword.php</strong></p>
  
  <pre><code>  &lt;?php 
  require_once('DB_Functions.php');
      $db = new DB_Functions();
      $forgotpassword = $_POST['forgotpassword'];
  
      $randomcode = $db-&gt;random_string();
      if(isset($_POST['forgotpassword'])){
         $hash = $db-&gt;hashSSHA($randomcode);
          $encrypted_password = $hash["encrypted"]; // encrypted password
          $salt = $hash["salt"];
          $subject = "Password Recovery";
          $message = "Hello User,nnYour Password is sucessfully changed. Your new Password is $randomcode . Login with your new Password and change it in the User Panel.nnRegards,nLearn2Crack Team.";
          $from = "contact@learn2crack.com";
          $headers = "From:" . $from;
       if ($db-&gt;isUserExisted($forgotpassword)) {
  
       $user = $db-&gt;forgotPassword($forgotpassword, $encrypted_password, $salt);
        if ($user) {
           $response["success"] = 1;
            mail($forgotpassword,$subject,$message,$headers);
           echo json_encode($response);
          }
          else {
         $response["error"] = 1;
        echo json_encode($response);
          }
       }
  
              // user is already existed - error response
  
          }
             else {
  
              $response["error"] = 2;
              $response["error_msg"] = "User not exist";
               echo json_encode($response);
  
  }
  
  ?&gt;
  </code></pre>
  
  <p><strong>DB_Functions.php</strong></p>
  
  <pre><code>    &lt;?php
   require_once('dbConnect.php');
  class DB_Functions {
  
      private $db;
  
  
      /**
       * Random string which is sent by mail to reset password
       */
  
  public function random_string()
  {
      $character_set_array = array();
      $character_set_array[] = array('count' =&gt; 7, 'characters' =&gt; 'abcdefghijklmnopqrstuvwxyz');
      $character_set_array[] = array('count' =&gt; 1, 'characters' =&gt; '0123456789');
      $temp_array = array();
      foreach ($character_set_array as $character_set) {
          for ($i = 0; $i &lt; $character_set['count']; $i++) {
              $temp_array[] = $character_set['characters'][rand(0, strlen($character_set['characters']) - 1)];
          }
      }
      shuffle($temp_array);
      return implode('', $temp_array);
  }
  
    public function isUserExisted($email) {
          $result = mysqli_query($this-&gt;db,"SELECT email from users WHERE email = '$email'");
          if($result)
          {
          $no_of_rows = mysqli_num_rows($result);
          if ($no_of_rows &gt; 0) {
              // user existed
              return true;
          }
          }else {
              // user not existed
              return false;
          }
      }
  
  
   public function hashSSHA($password) {
  
          $salt = sha1(rand());
          $salt = substr($salt, 0, 10);
          $encrypted = base64_encode(sha1($password . $salt, true) . $salt);
          $hash = array("salt" =&gt; $salt, "encrypted" =&gt; $encrypted);
          return $hash;
      }
  
  public function forgotPassword($forgotpassword, $newpassword, $salt){
      $result = mysqli_query("UPDATE `users` SET 'password` = '$newpassword'
                            WHERE `email` = '$forgotpassword'");
  
  if ($result) {
  
  return true;
  
  }
  else
  {
  return false;
  }
  }
  }
  ?&gt;
  </code></pre>
  
  <p><strong>dbConnect.php</strong></p>
  
  <pre><code>&lt;?php
      define('HOST','127.0.0.1:3307');
      define('USER','root');
      define('PASS','');
      define('DB','androiddb');
  
      //Connecting to Database
      $con= mysqli_connect(HOST,USER,PASS,DB) or die('Unable to Connect');
  ?&gt;
  </code></pre>
  
  <p>This is what I have tried so far, unfortunately it gives me a bunch of error ! Any help would be appreciated .</p>
  
  <p>I get tutorial from <a href="https://www.learn2crack.com/2013/08/develop-android-login-registration-with-php-mysql.html/4" rel="nofollow">here</a>.</p>
  
  <p><strong>Error</strong>(latest)</p>
  
  <blockquote>
    <p>Notice: Undefined index: forgotpassword in
    C:\xampp\htdocs\Android\CRUD\forgetPassword.php on line 4
    {"error":2,"error_msg":"User not exist"}</p>
  </blockquote>