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
sirTemplar
Forum Commoner
Posts: 65
Joined: Wed Dec 18, 2002 1:57 am

forgot password script!

Post by sirTemplar »

hi. i just found a send password script here. this is the script.


Code: Select all

<?php
--------------------------------------------------------------------------------
 
$db_host  = '';  
$db_user  = '';  
$db_pass  = '';  
$db_name  = '';  
$db_table = 'mytable';  
$conn = mysql_connect($db_host,$db_user,$db_pass);  
mysql_select_db($db_name,$conn);   

mt_srand((double)microtime() * 1000000);  
$charlist = "qwertyuiopasdfghjklzxcvbnm1234567890";  
$newpass = '';  
$max = strlen($charlist) - 1;  
for ($i = 0; $i < 10; $i++) {  
    $randnum = mt_rand(0, $max);  
    $newpass .= $charlist{$randnum};  
}  
$newpass2= md5($newpass);  
$email=$_POST["email"]; // this value is from a form wherein they input their email add 

$sql = "SELECT * FROM mytable where email = '$email'";  
$result = mysql_query($query);  
if(mysql_num_rows($result) == 0) {  
echo "Your email address is not in the database.";  
}  
else { 
$sql2 = "UPDATE mytable SET  
    password='$newpass2' 
    WHERE email='$email'";  
if ($result2 = mysql_query($sql2)) {  
$femail= "myemail@myemail.net";  
$temail= $email;  
$message="Hi there, as requested please find your new password below:\n\nPassword: $newpass\n\nPlease login and change your pass immediately";  
if(mail($temail,":: Password Reminder ::",$message,"From: $femail\n")) {  
echo "We have sent an email including your new pass to $email";  
} else {  
echo "Sorry, there was a problem sending your reminder. Please try again letter or contact an admin.";  
}  
} 
} 
?>
--------------------------------------------------------------------------------



the problem is i always get:
Your email address is not in the database.

though i'm sure that the email add exists! thanks.
evanz
Forum Newbie
Posts: 6
Joined: Wed May 19, 2004 8:44 am

Post by evanz »

try use _POST['email'] to see what happens
Post Reply