Pleas help, can't find bug.

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
User avatar
spamyboy
Forum Contributor
Posts: 266
Joined: Sun Nov 06, 2005 11:29 am
Location: Lithuania, vilnius

Pleas help, can't find bug.

Post 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';
}
?>
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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
User avatar
spamyboy
Forum Contributor
Posts: 266
Joined: Sun Nov 06, 2005 11:29 am
Location: Lithuania, vilnius

Post 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 !!! :)
User avatar
Buddha443556
Forum Regular
Posts: 873
Joined: Fri Mar 19, 2004 1:51 pm

Post by Buddha443556 »

Default case should probably not be first.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post by Charles256 »

at least in c++ default case MUST come last..going to assume it's the same for PHP.move the default :-D
User avatar
spamyboy
Forum Contributor
Posts: 266
Joined: Sun Nov 06, 2005 11:29 am
Location: Lithuania, vilnius

Post 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.
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post by Charles256 »

look at your code..see where it says "default: break;" move that below the part that says case
User avatar
spamyboy
Forum Contributor
Posts: 266
Joined: Sun Nov 06, 2005 11:29 am
Location: Lithuania, vilnius

Post by spamyboy »

Thank you, now it works :)
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post by Charles256 »

no problem. default case must always be the last case :-D glad to help
Post Reply