Results 1 to 9 of 9

Thread: Day 16 - Forget Password Feature - Become PHP Expert in 30 days

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2003
    Posts
    3,040

    Default

    Stefin, your program is missing 1 line.

    PHP Code:
    $userInfo mysqli_fetch_assoc($result); 
    This need to be added after code

    PHP Code:
    if ($result->num_rows == 0) {
        die(
    "User with email address <b>$email</b> not found");

    What that line do is fetch (means read, get, etc..) user information from MySQL query result.

    @annie made that mistake (but actual code worked, i verified), @sherly copied it @stefin reported the mistake :D

    @sherly

    http://php.flashwebhost.com/sherly/lost_password.html

    This is wrong code. You put code for index.html in lost_password.html

    Please reupload the code, try to understand, if you don't understand ask here, that help everyone.

    Now stefin asked the question, and we found a problem with posted codes.
    Become PHP Expert in 30 days
    FreeMarriage.com - Free Online Matrimonial
    FlashWebHost.com - Professional Web Hosting, Designing.

  2. #2
    Join Date
    Nov 2004
    Location
    India
    Posts
    65

    Default

    Code Fixed, Mail received with password.

    PHP Code:

     <?php
    if (isset($_POST['email'])) {    $email $_POST['email'];} else {    die('Please enter your email address');}
    $email trim($email);
    $db_server '127.0.0.1';$db_user 'fwhphp_user';$db_password 'k5BJRaX6SFbs';$db_name 'fwhphp_db';
    $mysqli = new mysqli($db_server$db_user$db_password$db_name);
    if (
    $mysqli->connect_errno) {    echo 'Connect failed: ' $mysqli->connect_error;    exit();}
    $sql "select * from users where email='$email'";
    $result $mysqli->query($sql);

    if (
    $result->num_rows == 0) {    die("User with email address <b>$email</b> not found");}
    $userInfo mysqli_fetch_assoc($result);
    $name $userInfo['name'];$password $userInfo['password'];mail($email,"Your password""Hello $name, your password is $password");
    echo 
    'New Password send to your email';

  3. #3
    Join Date
    Nov 2009
    Posts
    76,596

    Default

    I got email with password

    http://php.flashwebhost.com/sherly/lost_password.html
    http://php.flashwebhost.com/sherly/lost_password.php

    Code:
    <?php
    if (isset($_POST['email'])) {    
       $email = $_POST['email'];
    } else {    
       die('Please enter your email address');
    }
    
    $email = trim($email);
    
    $db_server = '127.0.0.1';
    $db_user = 'fwhphp_user';
    $db_password = 'k5BJRaX6SFbs';
    $db_name = 'fwhphp_db';
    
    $mysqli = new mysqli($db_server, $db_user, $db_password, $db_name);
    
    if ($mysqli->connect_errno) {    
    
    echo 'Connect failed: ' . $mysqli->connect_error;    
    exit();
    
    }
    
    $sql = "select * from users where email='$email'";
    
    $result = $mysqli->query($sql);
    
    if ($result->num_rows == 0) {    
    die("User with email address <b>$email</b> not found");
    
    }
    $userInfo = mysqli_fetch_assoc($result);
    
    $name = $userInfo['name'];
    $password = $userInfo['password'];
    mail($email,"Your password", "Hello $name, your password is $password");
    echo 'The password has been sent to the e-mail address specified';

  4. #4
    Join Date
    Sep 2003
    Posts
    3,040

    Default

    @stefin, good, the code lost formatting, but it is ok, may be problem with editor.

    @sherly, nice, now it works.
    Become PHP Expert in 30 days
    FreeMarriage.com - Free Online Matrimonial
    FlashWebHost.com - Professional Web Hosting, Designing.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •