title: Not resetting password
body: <p>I wanted to make a reset password script thing but it didn't work, it doesn't update the database for some reason.</p>
  
  <p>Code:</p>
  
  <pre><code>    &lt;?php 
  include 'header.php';
  
  error_reporting(0);
  session_start();
  $username = $_SESSION['username'];
  $userid = $_SESSION['id'];
  
   if (empty($username) &amp;&amp; empty($userid) ) {
  
  $form='
              &lt;table&gt;
              &lt;form action="forgotpass.php" method="POST"&gt;
                  &lt;tr&gt;
                      &lt;td&gt;Username :&lt;/td&gt;
                      &lt;td&gt;&lt;input type="text" name="user"&gt;&lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;td&gt;Email:&lt;/td&gt;
                      &lt;td&gt;&lt;input type="text" name="email"&gt;&lt;/td&gt;
                      &lt;td&gt;Must be a valid email address.&lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;td&gt;&lt;/td&gt;
                      &lt;td&gt;&lt;input type="submit" name="resetbtn" value="Reset password"&gt;&lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;/form&gt;
              &lt;/table&gt; ';
  
      $user = $_POST['user'];
      $email = $_POST['email'];
  
      if (isset($_POST['resetbtn'])) { 
  
          if ($user) {
  
                  if ($email) {
  
                      if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
  
                          require 'core/connect.php';
  
                          $query = mysqli_query($GLOBALS["___mysqli_ston"], "SELECT * FROM users WHERE username = '$user' ");
                          $numrows = mysqli_num_rows($query);
                          if ($numrows == 1) {
                          $row = mysqli_fetch_assoc($query);
                          $dbemail = $row['email'];
  
                              if ($email = $dbemail) {
  
                                 function better_crypt($input, $rounds = 7) {
                                 $salt = "";
                                 $salt_chars = array_merge(range('A','Z'), range('a','z'), range(0,9));
                                 for($i=0; $i &lt; 22; $i++) {
                                 $salt .= $salt_chars[array_rand($salt_chars)];
                                 }
                                 return crypt($input, sprintf('$2a$%02d$', $rounds) . $salt);
                                 }
                                 $password_hash = better_crypt($password);
                                 $password_hash = better_crypt($password, 10);
                                 $password_hash = better_crypt($password, 15);
                                 $new_pass = substr($password_hash, 0, 15);
  
                                  mysqli_query($GLOBALS["___mysqli_ston"], "UPDATE users SET password = '$new_pass' WHERE username = '$username' ");
                                  $query = mysqli_query($GLOBALS["___mysqli_ston"], "SELECT * FROM users WHERE username = '$user' AND password = '$new_pass' ");
                                  $numrows = mysqli_num_rows($query);
                                  if ($numrows == 1) {
  
                                      $site = "http://localhost/website";
                                      $webmaster = "Demo Site&lt;JadWalidSamadi@gmail.com&gt;";
                                      $headers = "From: $webmaster";
                                      $subject = "Password reset";
                                      $message = "You have asked for a password reset for Demo Site.\n";
                                      $message = "New password :";
                                      $message = "$new_pass";
                                      $message .="You must change your password as soon as you re-log in.";
  
                                          if (mail ($getemail, $subject, $message, $headers)) {
  
                                          echo '&lt;font color="green"&gt;Your new password has been sent to your email. &lt;/font&gt;';
                                          echo $email;
  
                                          } else {
  
                                          echo '&lt;font color="red"&gt;An error has occurred.Your activation email was not sent.&lt;/font&gt;';   
  
                                          }                                   
  
                                  }else {
  
                                  echo '&lt;font color="red"&gt;An error has occurred . Your password was not reset.&lt;/font&gt;';   
  
                                  }
  
                              }else{
  
                              echo '&lt;font color="red"&gt;You have provided an invalid username or email.&lt;/font&gt;';
                              echo $form;                                 
  
                              }
  
                          }else{
  
                          echo '&lt;font color="red"&gt;You have provided an invalid username or email.&lt;/font&gt;';
                          echo $form;                             
  
                          }
  
                          mysql_close();
  
                      } else {
  
                      echo '&lt;font color="red"&gt;You must provide a valid email.&lt;/font&gt;';
                      echo $form;                         
  
                      }
  
                  } else {
  
                  echo '&lt;font color="red"&gt;You must provide your email.&lt;/font&gt;';
                  echo $form;                         
  
                  }
  
          } else{
  
          echo '&lt;font color="red"&gt;You must provide your username.&lt;/font&gt;';
          echo $form;             
  
          }
  
      }else{
  
      echo $form;
  
      }
  
   }else{
  
      echo '&lt;font color="red"&gt;You must be logged out to be able to access this page\'s content.&lt;/font&gt;';   
  
   }
  
  include 'footer.php';
   ?&gt;
  </code></pre>