PHP成员重置密码表单没有提交(是的我再次)

时间:2013-03-12 12:24:20

标签: php

嗨再次,这是我几乎完成了该网站的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>

我很感谢你对此的帮助,因为它只是为了娱乐而学习。期待有希望听到一些人的回复。提前致谢。

2 个答案:

答案 0 :(得分:5)

请更正表格的拼写

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

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

希望这会解决您的问题

答案 1 :(得分: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>";