Page 1 of 1

Pleas help, can't find bug.

Posted: Mon Jan 02, 2006 8:47 pm
by spamyboy
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';
}
?>

Posted: Mon Jan 02, 2006 8:51 pm
by Chris Corbyn
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

:D

Posted: Mon Jan 02, 2006 9:09 pm
by spamyboy
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 !!! :)

Posted: Mon Jan 02, 2006 10:43 pm
by Buddha443556
Default case should probably not be first.

Posted: Tue Jan 03, 2006 9:04 am
by Chris Corbyn
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:

Code: Select all

<?php error_reporting(E_ALL); ?>
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 :D

Posted: Tue Jan 03, 2006 9:10 am
by Charles256
at least in c++ default case MUST come last..going to assume it's the same for PHP.move the default :-D

Posted: Tue Jan 03, 2006 9:52 am
by spamyboy
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.

Posted: Tue Jan 03, 2006 9:54 am
by Charles256
look at your code..see where it says "default: break;" move that below the part that says case

Posted: Tue Jan 03, 2006 10:08 am
by spamyboy
Thank you, now it works :)

Posted: Tue Jan 03, 2006 10:09 am
by Charles256
no problem. default case must always be the last case :-D glad to help