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

    Join Date
    Aug 2009
    Posts
    49
    Rep Power
    5

    Reset Password Form Error?


    Hi Everyone,

    I wrote a script to reset my password but when I press "reset password" it's giving me my first error message I'm not sure why. What do you guys think?

    It's giving me this message
    PHP Code:
    else {
         echo 
    "Please logout to view this page!!";

    Thanks!

    PHP Code:
    <?php
    session_start
    ();
    $url $_SERVER['REQUEST_URI']; //Getting Page url and storing in $url variable.
    $_SESSION['pageurls']="$url"//Now storing that $url variable in SESSION.

    $loggedinuser $_SESSION["id"];

    if (
    $loggedinuser == true){
        echo 
    "You can't be logged in to see this page. Please log out!";
    } else {

    include
    "connect_to_mysql3.php";


    if (!
    $user && !$id){

      if (
    $_POST['resetbtn']){
         
    // get the form data
         
    $user $_POST['user'];
         
    $email $_POST['email'];
         
         
    // make sure info. provided
         
    if ($user){
            if (
    $email){
               if ( (
    strlen($email >7) AND (strstr($email"@")) AND (strstr($email".")) ) ){
                   
    // connect to database
                   
    require("connect_to_mysql3.php");
                   
                   
    $query mysql_query("SELECT * FROM practice WHERE name='$user'");
                   
    $numrows mysql_num_rows($query);
                   if (
    $numrows == 1){
                      
    // get info about account
                      
    $row mysql_fetch_assoc($query);
                      
    $dbemail $row['email'];
                      
    // make sure emial is correct
                      
    if ($email == $dbemail){
                      
                        
    // generate password
                        
    $pass rand();
                        
    $pass md5($pass);
                        
    $pass substr($pass0,8);
                        
    // $pass = md5(md5());
                        
                        // update database with new password
                        
    mysql_query("UPDATE practice WHERE password='$password' WHERE username='$user'");
                        
                        
    // make sure password was changed
                        
    $query mysql_query("SELECT * FROM practice WHERE username='$user' AND password='$password'");
                        
    $numrows mysql_num_rows($query);
                        if (
    $numrows == 1){
                             
                              
    // email variables
                              
    $webmaster "bob@yahoo.com";
                              
    $headers "From: Bob<$webmaster>";
                              
    $subject "Your new password";
                              
    $message "Hello, your password has been reset. Yout new password is below.\n";
                              
    $message .= "Password: $pass\n";
                              
                              if (
    mail($email$subject$message$headers) ){
                                 echo 
    "Your password has been reset. An email has been sent with your new password.";          
                           } else
                              echo 
    "An error has occured and your email was not sent.";
                        } else 
                           echo 
    "An error has occured and the password was not reset.";      
                      }
                       else
                         echo 
    "We couldn't find that email address in our database.";                  
                   } 
                    else 
                      echo 
    "Username was not found";
                   
                   
    mysql_close();
              }
              else 
                 echo 
    "Please enter valid email";      
            }
            else 
                 echo 
    "Please enter your email";    
         }
         else 
           echo 
    "Please enter your username";
         
         
      }
       echo 
    "<form action='forgot.php' method='post'>
        <table>
        <tr>
          <td>Username:</td>
          <td><input type='text' name='user'/></td>
        </tr>
        <tr>
          <td>Email:</td>
          <td><input type='text' name='email'/></td>
        </tr>
        <tr>
          <td><input type='submit' name='resetbtn' value='Reset Password'/></td>
        </tr>
        </table>
        </form"
    ;
    } else {
         echo 
    "Please logout to view this page!!";



    }
    ?>
  2. #2
  3. Web Developer
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2006
    Posts
    480
    Rep Power
    112

    Your code seems improper


    Your code seems not proper.. As you have set condition if User or Id not found then echo the message "Please logout to view this page!!"

    So it is obvious thing by default it will not found.and definitely that message will appear.

    See your below code structure..

    What is $id? What is $user? You haven't specify that how it's value set?

    PHP Code:

    if (!$user && !$id) { 

      if (
    $_POST['resetbtn']){
      }
    }
    else
    {


    Comments on this post

    • ManiacDan agrees
    I will try my best !!!

IMN logo majestic logo threadwatch logo seochat tools logo