What am I doing wrong!! Password forgot [SOLVED]

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
melindaSA
Forum Commoner
Posts: 99
Joined: Thu Oct 02, 2003 7:34 am

What am I doing wrong!! Password forgot [SOLVED]

Post by melindaSA »

I am trying to retrieve a password from the database if the user forgot his password, and then email to user. It sends the email with no password, here is what the email looks like:
Your Password for Wholesale at xxxxxxxxxxxxx.com is

Go here to login http://www.xxxxxxx.com/login.php
Here is my code:

Code: Select all

<?php
require_once('db_fns.php');


//creating short variable name
  $email = $HTTP_POST_VARS&#1111;'email'];

  if (notify_password($email, $password))
  { 
      echo 'Your password has been sent to your email address.';
    
  }
  else
    echo 'Your email address is not in the database.'
           .' Please send email to email@xxxxxxx.net to request password.';
?>

Code: Select all

<html>

<head>
<title>Forgot Password</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="includes/style-sheet.css" rel="stylesheet" type="text/css">
</head>

<body>
<p>&nbsp;</p>
<p class="bodytxt">Fill in your email address, and we will email your password.</p>
<form method="POST" action="sendpass.php">
  <p><input type="text" name="email" size="37"></p>
  <p><input type="submit" value="Submit" name="B1"></p>
</form>
<p>&nbsp;</p>

</body>

</html>

Code: Select all

<?php

function db_connect()
{
   $result = mysql_pconnect('MySQLHost', 'xxxxxxxx', 'xxxxxx'); 
   if (!$result)
      return false;
   if (!mysql_select_db('xxxxxx'))
      return false;

   return $result;
}



function notify_password($email, $password)
// email password to user
{
    if (!($conn = db_connect()))
      return false;
    $result = mysql_query("select * from tbl_scmember
                            where email='$email'");
                            
    if (mysql_num_rows($result)==0)
    {
      return false; // email not in db
    }
    else
    {
      $email = mysql_result($result, 0, 'email');
      $from = "From: info@xxxxxx.com \r\n";
      $mesg = "Your Password for xxxxxxx is $password \r\n"
              ."Go here to login http://www.sxxxxxxxxx.com/login.php \r\n";
      
      
      if (mail($email, 'Password for xxxxxxxxx', $mesg, $from))
        return true;      
      else
        return false;     
    }
} 

?>
Please any help would be appreciated!!


feyd | Help us, help you. Please use

Code: Select all

and

Code: Select all

tags where approriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
Last edited by melindaSA on Tue Jan 04, 2005 7:01 am, edited 2 times in total.
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

You never set $password in db_fns.php.

Add this line:

Code: Select all

$password = mysql_result($result, 0, 'password');
below:

Code: Select all

$email = mysql_result($result, 0, 'email');
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

please use the

Code: Select all

tags melinda.
melindaSA
Forum Commoner
Posts: 99
Joined: Thu Oct 02, 2003 7:34 am

Post by melindaSA »

Thank you it works! :D

Sorry used "code" instead of "PHP" for the post....... :oops:
Post Reply