Jump to content

Forgot Password/Username Script


HDFilmMaker2112

Recommended Posts

I'm having a little issue with this script. It's returning:

 

"Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/zyquo/public_html/makethemoviehappen.com/forgot_password.php on line 89"

(Line 89 is: $num_rows1 = mysql_num_rows($result1);)

 

and

 

"New password could not be generated. If you continue to have issues, please email general@makethemoviehappen.com for assistance."

 

I checked the database and the random password generation did run, and it was inserted into the database. So it's just not detecting that it ran, so it's not sending the email. Any ideas on why?

 

I also checked what is returned in the $result1 variable and it's the number 1.

 

 

elseif($_GET['forgot']=="password"){ 

function &generatePassword($length=9, $strength=0) { 
        $vowels = 'aeiuy'; 
        $consonants = 'bcdfghjkmnpqrstwz'; 
        if ($strength & 1) { 
                $consonants .= 'BCDFGJLMNPQRSTVXZ'; 
        } 
        if ($strength & 2) { 
                $vowels .= "AEIUY"; 
        } 
        if ($strength & 4) { 
                $consonants .= '23456789'; 
        } 
        if ($strength &  { 
                $consonants .= '@#$%'; 
        } 
  
        $password = ''; 
        $alt = time() % 2; 
        for ($i = 0; $i < $length; $i++) { 
                if ($alt == 1) { 
                        $password .= $consonants[(rand() % strlen($consonants))]; 
                        $alt = 0; 
                } else { 
                        $password .= $vowels[(rand() % strlen($vowels))]; 
                        $alt = 1; 
                } 
        } 
        return $password; 
} 

$new_password =& generatePassword(); 

$username=$_POST['username']; 
$sql="SELECT * FROM $tbl_name WHERE Username='$username' AND Email='$email' AND Amount='$donation_amount'"; 
$result=mysql_query($sql); 
$num_rows = mysql_num_rows($result); 

if($num_rows==1){ 
$sql1="UPDATE $tbl_name SET Password='$new_password' WHERE Username='$username' AND Email='$email' AND Amount='$donation_amount'"; 
$result1=mysql_query($sql1); 
$num_rows1 = mysql_affected_rows($result1); 

if($num_rows1==1){ 
$content.='<p class="center">New password generated. It has been emailed to the email address provided.</p><br />'; 
$message='Some one (hopefully you) requested a new password be generated for your account on Make the Movie Happen. 
Below is the newly generated password: 

Password: '.$new_password.' 

Once you log-in, please change your password. 

Thank You, 
Make the Movie Happen Support Team 
'; 
mail($email, 'Make the Movie Happen - New Password', $message, 'From: general@makethemoviehappen.com'); 
} 

else{ 
$content.='New password could not be generated.  
If you continue to have issues, please email <a href="mailto:general@makethemoviehappen.com">general@makethemoviehappen.com</a> for assistance.'; 
} 

} 
else{ 
header("Location: ./index.php?forgot&e=1"); 
} 
}

Link to comment
Share on other sites

Post the revised code snippet . . .

 

hmm... I was using

if($num_rows==1){
$sql1="UPDATE $tbl_name SET Password='$new_password' WHERE Username='$username' AND Email='$email' AND Amount='$donation_amount'";
$result1=mysql_query($sql1);
$num_rows1=mysql_affected_rows($result1);

 

I switched it to

$num_rows1=mysql_affected_rows();

without $result1 inside the parenthesis and now it's working.

 

Any idea why it wasn't working with the variable in it?

 

And thanks by the way for the correction to mysql_affected_rows... first time I needed to calculate rows based on a database update.

Link to comment
Share on other sites

Add your link to mysql_affected_rows($dblinkhere); You'll have to place the link that holds that connection where $dblinkhere is.

 

This is what I ment but kept the $result1 there for no reason. mysql_affected_rows() works just like that .. so whatever the last mysql_connect() database was, will be the link identifier. So on your last query $result1 was not the link identifier and that's why it flagged you with the warning.

 

So using the mysql_affected_rows($dblinkhere); or mysql_affected_rows(); would both work.

 

Don't forget to mark solved.  8)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.