Help with my Forgot Password script...

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
cooler75
Forum Commoner
Posts: 40
Joined: Wed May 29, 2002 2:43 pm
Location: RichIsland

Help with my Forgot Password script...

Post by cooler75 »

Hello,
I have posted this question in other forum too.

Anyways, my question is this, I generated password for my users using PASSWORD (), now i have a forgot password page where users can input their email to have a new password sending to them. I have the UPDATE part done successfully for the script. However, when users receive email they can only see their new password, but their username is blank.

here is the script,..

Code: Select all

$newpass = substr(md5(time()),0,6);

	$sql = "UPDATE mgrs SET mgrpass = PASSWORD('$newpass') WHERE mgremail='$email'";

	mysql_query($sql);  

	$sql = mysql_query("SELECT * FROM mgrs WHERE mgremail='$email'",$link);

	while ($a_row =mysql_fetch_array ($sql) )
		
		{
		
		
    $subject = "Your Login and Password";

		$fromName = $yourname;

		$fromAddres = $youremail;

		$message = "Your login name is: $rowїmgr]\r\nYour password is: $newpass\r\n";



		$temp = mail($email, $subject, $message, "From: ".$fromName." <".$fromAddress.">") or print "Could not send mail.<BR><BR><P>";

		if ($temp = true) &#123;print "Check your email for username and new password<P> ";&#125;


		&#125;
The email received will be something like this:

Code: Select all

Your login name is :
Your password is : 6063ad
The login name is blank...Can somebody look and check my script and let me know what i did wrong here?

thanks a bunch.
User avatar
QWERTY
Forum Newbie
Posts: 20
Joined: Sat Jun 29, 2002 10:57 am
Location: Slovenia

...

Post by QWERTY »

Try this:

Code: Select all

$newpass = substr(md5(time()),0,6); 

   $sql = "UPDATE mgrs SET mgrpass = PASSWORD('$newpass') WHERE mgremail='$email'"; 

   mysql_query($sql);  

   $sql = mysql_query("SELECT * FROM mgrs WHERE mgremail='$email'",$link); 

   while ($a_row =mysql_fetch_array ($sql) ) 
       
      &#123; 
       
       
    $subject = "Your Login and Password"; 

      $fromName = $yourname; 

      $fromAddres = $youremail; 

      $message = "Your login name is: $a_row&#1111;mgr]\r\nYour password is: $newpass\r\n"; 



      $temp = mail($email, $subject, $message, "From: ".$fromName." <".$fromAddress.">") or print "Could not send mail.<BR><BR><P>"; 

      if ($temp = true) &#123;print "Check your email for username and new password<P> ";&#125; 


      &#125;
Line:

Code: Select all

$message = "Your login name is: $row&#1111;mgr]\r\nYour password is: $newpass\r\n";
Should be:

Code: Select all

$message = "Your login name is: $a_row&#1111;mgr]\r\nYour password is: $newpass\r\n";
Becaose:

Code: Select all

while ($a_row =mysql_fetch_array ($sql) )
Variable is $a_row and not $row...
cooler75
Forum Commoner
Posts: 40
Joined: Wed May 29, 2002 2:43 pm
Location: RichIsland

Post by cooler75 »

Hi thanks,
it works. My mistake here, i should be more careful

thank you'
Post Reply