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
spamyboy
Forum Contributor
Posts: 266 Joined: Sun Nov 06, 2005 11:29 am
Location: Lithuania, vilnius
Post
by spamyboy » Mon Jan 02, 2006 8:47 pm
Where is bug ?!?!?
Code: Select all
<?
include 'db.php';
switch($_POST['recover']){
default:
break;
case "recover":
recover_pw($_POST['email_address']);
break;
}
function recover_pw($email_address){
if(!$email_address){
echo "You forgot to enter your Email address
<strong>Knucklehead</strong><br />";
exit();
}
// quick check to see if record exists
$sql_check = mysql_query("SELECT * FROM users WHERE email_address='$email_address'");
$sql_check_num = mysql_num_rows($sql_check);
if($sql_check_num == 0){
echo "No records found matching your email address<br />";
exit();
}
// Everything looks ok, generate password, update it and send it!
function makeRandomPassword() {
$salt = "abchefghjkmnpqrstuvwxyz";
srand((double)microtime()*1000000);
$i = 0;
while ($i <= 7) {
$num = rand() % 33;
$tmp = substr($salt, $num, 1);
$pass = $pass . $tmp;
$i++;
}
return $pass;
}
$random_password = makeRandomPassword();
$db_password = md5($random_password);
$sql = mysql_query("UPDATE users SET password='$db_password'
WHERE email_address='$email_address'");
$subject = "Atkurtas jusu slaptazodis.";
$message = "Prasome uzsirasyti sita koda.
Taigpogi jus galite pasikeisti ji, i jums labiau patinkanti (puslapyje).
Naujas kodas: $random_password
Aciu!
Administracija
";
mail($email_address, $subject, $message, "From: spamyboy Webmaster<spamyboy@gmail.com>\n
X-Mailer: PHP/" . phpversion());
echo "Patikrinkite savo e-pasto dezute.<br />";
include 'login_form.html';
}
?>
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098 Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia
Post
by Chris Corbyn » Mon Jan 02, 2006 8:51 pm
Might help if we knew what the problem is
General guidlines for getting quick answers:
1. Explain what the problem is
2. Post the code
3. Post any errors
4. Tell us anything you've already tried and failed
spamyboy
Forum Contributor
Posts: 266 Joined: Sun Nov 06, 2005 11:29 am
Location: Lithuania, vilnius
Post
by spamyboy » Mon Jan 02, 2006 9:09 pm
HRRRRrrr.....
Ok there is nor errors, it should diplay errors bet he dont !!!
And my englsih is horrible, so it's not easy to explain !!!
Buddha443556
Forum Regular
Posts: 873 Joined: Fri Mar 19, 2004 1:51 pm
Post
by Buddha443556 » Mon Jan 02, 2006 10:43 pm
Default case should probably not be first.
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098 Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia
Post
by Chris Corbyn » Tue Jan 03, 2006 9:04 am
HRRRRrrr.....
Ok there is nor errors, it should diplay errors bet he dont !!!
Is the email failing to be received or is the script itself having problems? There well known issues with email sent using mail() getting filtered by junk mail filters. You might want to have a look at phpMailer which is considered the "standard" method of sending email with PHP.
Also, if you're expecting errors in the script you might want to try adding this line of code to the top of your script:
And my englsih is horrible, so it's not easy to explain !!! Smile
Not a problem at all, you write clear enough for me to understand
Hope you get it sorted
Charles256
DevNet Resident
Posts: 1375 Joined: Fri Sep 16, 2005 9:06 pm
Post
by Charles256 » Tue Jan 03, 2006 9:10 am
at least in c++ default case MUST come last..going to assume it's the same for PHP.move the default
spamyboy
Forum Contributor
Posts: 266 Joined: Sun Nov 06, 2005 11:29 am
Location: Lithuania, vilnius
Post
by spamyboy » Tue Jan 03, 2006 9:52 am
MHm... migth be stupid question...
What is "Default case" ?
Code: Select all
Not a problem at all, you write clear enough for me to understand Smile
Maybe my english is not so wery bad, but it's not enough good to explain you all error's.
Charles256
DevNet Resident
Posts: 1375 Joined: Fri Sep 16, 2005 9:06 pm
Post
by Charles256 » Tue Jan 03, 2006 9:54 am
look at your code..see where it says "default: break;" move that below the part that says case
spamyboy
Forum Contributor
Posts: 266 Joined: Sun Nov 06, 2005 11:29 am
Location: Lithuania, vilnius
Post
by spamyboy » Tue Jan 03, 2006 10:08 am
Thank you, now it works
Charles256
DevNet Resident
Posts: 1375 Joined: Fri Sep 16, 2005 9:06 pm
Post
by Charles256 » Tue Jan 03, 2006 10:09 am
no problem. default case must always be the last case
glad to help