0

再次嗨,我几乎完成了网站的 gubbings,但我不知道为什么这个重置密码页面没有通过任何它的程序。我确定这又是一件小事,但我看不到它,似乎我的重置按钮根本不起作用,但当我调用它时它的拼写正确,而且据我所知,所有括号都是正确的。我敢肯定,我越习惯这些错误,我自己就越会发现它们。为愚蠢的问题道歉。

这是我的代码:

<?php
error_reporting (E_ALL ^ E_NOTICE);
session_start();
$userid = $_SESSION['userid'];
$username = $_SESSION['username'];
?>
<html>
<head>
<title> Member system : Forgot password</title>
</head>
<body>
<?php
if(!$username && !$userid) {

    if($_POST['resetbtn']) {
        //get form data
        $user = $_POST['user'];
        $email = $_POST['email'];

        //make sure info provided
        if($user) {
            if($email) {
                if((strlen($email) > 7) && (strstr($email, "@")) &&    (strstr($email, ".")) ) {
                    require("./connect.php");

                    $query = mysql_query("SELECT * FROM user WHERE   username='$user'");
                    $numrows = mysql_num_rows($query);
                    if($numrows == 1) {
                        // info about account
                        $row = mysql_fetch_assoc($query);
                        $dbemail = $row['email'];

                        //make sure email is correct
                        if($email == $dbemail) {
                            // generate a password
                            $pass = rand();
                            $pass = md5($pass);
                            $pass = substr($pass, 0, 15);
                            $password =   md5(md5("12345".$pass."54321"));

                            //update db with new pass
                            mysql_query("UPDATE user SET  password='$password' WHERE username='$user'");

                            //make sure password was changed
                            $query = mysql_query("SELECT * FROM  user WHERE username='$user' AND password='$password'");
                            $numrows = mysql_num_rows($query);
                            if($numrows == 1) {
                                //create our email variables
                                $webmaster =  "mwilkins877@gmail.com";
                                $headers = "From:  Mike<$webmaster>";
                                $subject = "Your new password";
                                $message = "Your password has been reset, your new password is below. \n";
                                $message .= "Password: $pass\n";

                                echo $pass."<br/>";
                                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 wasnt sent containing your new password";
                            }
                            else
                                echo "An error has occured and the password was not set";
                        }
                        else
                            echo "You have entered the wrong email address";

                    }
                    else 
                        echo "The user name was not found";

                    mysql_close();
                }
                else "Please enter a valid email address";
            }
            else
                echo "please enter your email";
        }
        else
            echo "Please enter your user name";
    }
    else
        echo"<from action='./forgotpass.php' method='post'>
        <table>
        <tr>
            <td>User name</td>
            <td><input type='text' name='user'/></td>
        </tr>
        <tr>
            <td>email</td>
            <td><input type='text' name='email'/></td>
        </tr>
        <tr>
            <td></td>
            <td><input type='submit' name='resetbtn' value='Reset password'/>  </td>
        </tr>
        </table>
        </form>";
}
else
    echo "Please log out to view this page";
?>
</body>
</html>

我会很感激你在这方面的帮助,因为这只是我为了好玩而学习的。期待听到有人希望的回音。提前致谢。

4

2 回答 2

5

请更正表格的拼写

echo"<from action='./forgotpass.php' method='post'>

echo"<form action='./forgotpass.php' method='post'>

希望这能解决您的问题

于 2013-03-12T12:29:35.207 回答
0

试试这个。它为我工作。

<?php
error_reporting (E_ALL ^ E_NOTICE);
session_start();
$userid = $_SESSION['userid'];
$username = $_SESSION['username'];
?>
<body>
<?php
if(!$username && !$userid) {

    if($_POST['resetbtn']) {
        //get form data
        $user = $_POST['user'];
        $email = $_POST['email'];

        //make sure info provided
        if($user) {
            if($email) {
                if((strlen($email) > 7) && (strstr($email, "@")) &&    (strstr($email, ".")) ) {
                    require("./connect.php");

                    $query = mysql_query("SELECT * FROM user WHERE   username='$user'");
                    $numrows = mysql_num_rows($query);
                    if($numrows == 1) {
                        // info about account
                        $row = mysql_fetch_assoc($query);
                        $dbemail = $row['email'];

                        //make sure email is correct
                        if($email == $dbemail) {
                            // generate a password
                            $pass = rand();
                            $pass = md5($pass);
                            $pass = substr($pass, 0, 15);
                            $password =   md5(md5("12345".$pass."54321"));

                            //update db with new pass
                            mysql_query("UPDATE user SET  password='$password' WHERE username='$user'");

                            //make sure password was changed
                            $query = mysql_query("SELECT * FROM  user WHERE username='$user' AND password='$password'");
                            $numrows = mysql_num_rows($query);
                            if($numrows == 1) {
                                //create our email variables
                                $webmaster =  "mwilkins877@gmail.com";
                                $headers = "From:  Mike<$webmaster>";
                                $subject = "Your new password";
                                $message = "Your password has been reset, your new password is below. \n";
                                $message .= "Password: $pass\n";

                                echo $pass."<br/>";
                                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 wasnt sent containing your new password";
                            }
                            else
                                echo "An error has occured and the password was not set";
                        }
                        else
                            echo "You have entered the wrong email address";

                    }
                    else 
                        echo "The user name was not found";

                    mysql_close();
                }
                else "Please enter a valid email address";
            }
            else
                echo "please enter your email";
        }
        else
            echo "Please enter your user name";
    }
    else
        echo"<form action='./forgotpass.php' method='post'>
        <table>
        <tr>
            <td>User name</td>
            <td><input type='text' name='user'/></td>
        </tr>
        <tr>
            <td>email</td>
            <td><input type='text' name='email'/></td>
        </tr>
        <tr>
            <td></td>
            <td><input type='submit' name='resetbtn' value='Reset password'/>  </td>
        </tr>
        </table>
        </form>";
于 2013-03-12T12:49:51.647 回答