#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    16
    Rep Power
    0

    How to create a forgot password in login page?


    hello,

    I want to create a forgot password in my login page.

    This is my codings but i am getting error.
    The erroe is. "no such login in the system. please try again..

    forgot_password.php

    <?php
    if(isset($_POST['submit']))
    {
    mysql_connect("localhost", "root", "") or die(mysql_error());
    mysql_select_db("recruiter") or die(mysql_error());

    $id = $_POST['id'];
    }
    $sql="SELECT * FROM login WHERE id='.$id.'";
    $r = mysql_query($sql);
    if(!$r) {

    $err=mysql_error();

    print $err;

    exit();
    }

    if(mysql_affected_rows()==0)
    {

    print "no such login in the system. please try again.";

    exit();
    }
    else {

    $row=mysql_fetch_array($r);

    $password=$row&lt;"password"&gt;;

    $email=$row&lt;"email"&gt;;

    $subject="your password";

    $header="from:you@yourdomain.com";

    $content="your password is ".$password;

    mail($email, $subject, $row, $header);

    print "An email containing the password has been sent to you";

    }
    ?>

    for.php

    <html>
    <head>
    </head>
    <body>
    <form name="forgot" method="post" action="forgot_password.php">
    Enter ur id:
    <input name="id" type="text" value="" />

    <input type="submit" name="submit" value="submit"/>
    <input type="reset" name="reset" value="reset"/>
    </form>

    </body>
    </html>


    Please solve me.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,464
    Rep Power
    594
    1) Please enclose your PHP code in [ PHP ] tags. See ManiacDan's New User Guide.
    2) You are using the wrong function for a non-update query. You want 'mysql_num_rows' not 'mysql_affected_rows'. For a SELECT there are no affected rows.
    3) You should should not be using the depreciated mysql extensions. Switch to PDO.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  4. #3
  5. A Change of Season
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    2,664
    Rep Power
    171
    This is not secure
    PHP Code:
    mysql_connect("localhost""root""") or die(mysql_error());
    mysql_select_db("recruiter") or die(mysql_error()); 
    You don't need
    Code:
    SELECT *
    * is not necessary, just get email column and in stead of emailing them the password, you have to send them a link they can follow and choose the new password. When they reset it salt it and do not keep a copy of the none- encrypted password in the database. Place your code between php tags and brush your teeth before you go to bed.
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    8
    Rep Power
    0
    Here I’m getting to simply offer you the particular code required, if a user forgets their countersign. You in fact got to embrace the code that connects to the info along side all of your hypertext markup language, CSS and JavaScript code. All of this code would reside between the body tags of your hypertext markup language.

    The script asks for associate degree email address. we have a tendency to then make certain the e-mail belongs to a legitimate user. we alter that users countersign and email it back to them.


    if (isset($_POST['submitted'])) the shape.

    if (empty($_POST['email'])) { // Validate the e-mail address.

    $uid = FALSE;

    echo ‘

    You forgot to enter your email address!
    ’;

    Checks if the shape below has been submitted. Then it checks that associate degree email address has been entered with the empty() operate. If not we have a tendency to warn the traveller.

    } else wherever email=’”. escape_data($_POST['email']) . “‘”;

    $result = mysql_query ($query) or trigger_error(“Query: $query\n
    MySQL Error: ” . mysql_error());

IMN logo majestic logo threadwatch logo seochat tools logo