Results 1 to 7 of 7

Thread: Day 17 - Include: Easy cut and paste for Programmers - Become PHP Expert in 30 days

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2003
    Location
    india
    Posts
    11,527

    Default

    http://php.flashwebhost.com/annie/

    The password has been sent to the e-mail address specified

    PHP Code:
     <?php

    include "includes/database.php"

    if (isset(
    $_POST['email'])) {
        
    $email $_POST['email'];
    } else {
        die(
    'Please enter your email address');
    }

    $email trim($email);

    $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';

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

    Default

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

    The password has been sent to the e-mail address specified

    Code:
    <?php
    
    include "includes/database.php"; 
    
    if (isset($_POST['email'])) {    
       $email = $_POST['email'];
    } else {    
       die('Please enter your email address');
    }
    
    $email = trim($email);
    
    $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';

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

    Default

    http://php.flashwebhost.com/stefin/lost_password.php
    New Password send to your email

    This one was pretty good and interesting, i like copy pasting

    PHP Code:


    <?php
    include "includes/database.php";  

    if (isset(
    $_POST['email'])) {    $email $_POST['email'];} else {    die('Please enter your email address');}
    $email trim($email);


    $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';
    Last edited by stefin; 08-03-2014 at 02:29 AM.

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

    Default

    Nice. We can keep frequently used code in another file and include them as needed.
    Become PHP Expert in 30 days
    FreeMarriage.com - Free Online Matrimonial
    FlashWebHost.com - Professional Web Hosting, Designing.

  5. #5
    Join Date
    Nov 2009
    Location
    kerala
    Posts
    19,076

    Default

    http://php.flashwebhost.com/sibichan..._password.html

    Yes, I got the mail with password

    I used 'require' in lost_password.php

    PHP Code:

    <?php
    require "includes/database.php";  
    if (isset(
    $_POST['email'])) {

        
    $email $_POST['email'];

    } else {

        die(
    'Please enter your email address');}
    // now we have $email variable.

    // $email can contain space if user enter white space..

    // So lets remove any white space char using trim() function.
    $email trim($email);
    // lets write an SQL statement to search our users table

    // to find the user having email address == $email
    $sql "select * from users where email='$email'";
    // In above line, we used single quotes between email, because it is a string.
    // Now time to execute the SQL statement.

    $result $mysqli->query($sql);
    // lets see how many records found in database

    // If num_rows is 0, no user found
    if ($result->num_rows == 0) {

        die(
    "User with email address <b>$email</b> not found");

    }
    // lets get the user record from MySQLi result
    $userInfo mysqli_fetch_assoc($result);
    // $userInfo is an associate array.

    // Lets print it.

    // Now you can see all information about the user, including password.
    $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';

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

    Default

    Good, require is better, but used include as everyone understand the meaning of the word and is easy to relate to what it do - include code from other file.
    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
  •