0

我是 php 新手,所以我使用了一个 Youtube 教程来创建这个脚本,但是上传者似乎已经消失了,所以我不能问他任何问题。我的登录表单似乎工作正常,但注册表是我遇到问题的地方

我已经从代码中删除了所有 html 和所有错误 else 语句以尝试消除错误消息,但我似乎找不到它。错误总是发生在我的脚本末尾。

有什么建议么

        <?php

        if ( $_POST['registerbtn'] ) {
    //makes sure email, username is valid
    $getuser = $_POST['user'];
    $getemail = $_POST['email'];
    $getpass = $_POST['pass'];
    $getretypepass = $_POST['retypepass'];

    if (!isset($getuser))
    {
        $error = "user not set ";
    } 

    if ($getuser) {
        if($getemail) {
            if($getpass) {
                if ($getretypepass) {
        require("connection.php");

                            $query = mysql_query("SELECT * FROM          users WHERE username ='$getuser'");
                            $numrows = mysql_num_rows($query);
                            if ($numrows == 0) {
                            $query = mysql_query("SELECT * FROM users WHERE email ='$getemail'");
                            $numrows = mysql_num_rows($query);
                            if ($numrows == 0) {

                                $password = md5(md5("19Dvdnj".$password."jndfFf20"));
                                $date = date("F d, Y");
                                $code = md5(rand());

                                mysql_query("INSERT INTO users VALUES ('', '$getuser', '$password', '$getmail', '0', '$code', '$date')");

                                $query = mysql_query("SELECT * FROM users WHERE username='$getuser'");
                                $numrows =mysql_num_rows($query);
                                if ($numrows == 1) { 

                                $site ="http://www.inn.leedsmet.ac.uk/~c3314283/iis/register.php";
                                $webmaster = "admin@leedsmet.com";
                                $headers = "From: $webmaster";
                                $subject ="Activate your Account";
                                $message = "Thanks for registering. Click below to activate your account.\n";
                                $message .= "$site/activate.php?user=$getuser&code=$code";
                                $message .= "You must activate your account to login";

                                if (mail($getmail, $subject, $message, $headers)){
                                    $errormsg = "You have been registered you must activate your account sent from the the activation link sent to<b>$getemail</b>";
                                    $getuser = "";
                                    $getemail = "";
                                }



                            mysql_close();





        $form ="<form action='register.php' method='post'>
        <table>
        <tr>
    <td></td>
    <td><font color='red'>$errormsg</font></td>
        </tr>

<tr>
    <td>Username:</td>
    <td><input type='text' name='user' value ='$getuser'/></td>
</tr>
    <tr>
        <td>Email:</td>
        <td><input type='text' name='email' value ='$getemail'/></td>
    </tr>
        <tr>
    <td>Password:</td>
    <td><input type='password' name='pass' value =''/></td>
        </tr>       
    <tr>
    <td>Retype:</td>
    <td><input type='password' name='retypepass' value =''/></td>
        </tr>   
    <tr>
    <td></td>
    <td><input type='submit' name='registerbtn' value ='Register'/></td>
        </tr>   
        </table>
        </form>";
        {
        echo $form;
        }
        ?>
4

2 回答 2

2

尝试自动格式化(自动缩进)你的代码。如果您没有允许这样做的编辑器,请使用Sublime TextNotepad++之类的编辑器。:-) 在类似情况下它会为您节省大量时间;而不是试图在这种情况下定位问题,自动格式化后的问题会盯着你的脸。:-)

}我相信您if

{
    echo $form;
}

显然,如果是这种情况,发生了非常错误的事情,可能需要更多}的时间来修复你的代码。

这可能是复制和粘贴问题。也许您没有复制您在您提到的 Youtube 教程中找到的最后几行代码。

于 2012-12-02T02:37:06.503 回答
1

使用任何带有语法高亮的代码编辑器(例如 Notepad++)都会清楚地告诉你你缺少一个}.

于 2012-12-02T02:25:44.483 回答