Location: PHPKode > projects > PhpMyInventory > pmi281/forgotPW.php
<?
  Include("Includes/global.inc.php");

  If ($btnSubmit) {
      $strEmail = validateEmail("Email Address", $txtEmail, TRUE);

      If (!$strError) {
           $strSQL = "SELECT id, userID FROM tblSecurity WHERE email='$strEmail'";
           $result = dbquery($strSQL);
           $row = mysql_fetch_row($result);
           If ($row[0] == "") {
                $strError = "That email address does not exist in our database.";
           }

           If (!$strError) {
                $strTempString = "ABCDEFGHIJKLMNPQRSTUVWXYZ123456789";
                for ($i = 0; $i < 8; $i++) {
                     $intPos = rand(0, 33);
                     $strTempChar = substr($strTempString, $intPos, 1);
                     $strPassword = $strPassword.$strTempChar;
                }

                $strPassword2 = md5($strPassword);
                $strSQL3 = "UPDATE tblSecurity SET password='$strPassword2' WHERE id=".$row[0];
                $result3 = dbquery($strSQL3);

                $msgBody = "Your username is '".$row[1]."' and your temporary password is '$strPassword'.";
                mail($strEmail, "PMI password changed: ".date("m-d-Y"), $msgBody,
                  "From: $adminEmail\r\nReply-To: $adminEmail\r\n");

                $strError = "A new password has been emailed to the account you provided. ";
                $strError = $strError."You will be able to change this new, temporary password to ";
                $strError = $strError."whatever you wish after logging in.";
           }
      }
  }

  writeHeader("Forgot Your Password?");
  declareError(TRUE);
?>

<p>Please enter your email address below:<br>

<form name="form1" method="POST" action="forgotPW.php">
  <p><table border='0' width='415' cellpadding='2'>

    <tr>
      <td width='115'>Email Address:</td>
      <td width='300'><input type="text" name="txtEmail" value="<?echo $strEmail;?>" size="40" maxlength="50"></td>
    </tr>

  </table><p>

  <input type="hidden" value="Submit" name="btnSubmit">
  <input type="submit" value="Submit" name="btnSubmit">
  <input type="reset" value="Reset" name="reset">
</form>

<?
  writeFooter();
?>
Return current item: PhpMyInventory