0

我一直在尝试创建一个会员登录页面以链接到我的网站。我的 PHP 页面中有许多嵌套的 If,但是无论我尝试什么,我都会从第一个 else 语句中收到 $errormsg。

我设法改变这一点的唯一方法是在代码底部(表格之前)添加一个额外的空 else,当我单击 reigisterbtn 时,我要么收到第一个 else 结果,要么收到一个空白页,什么都不显示。

我错过了一些非常明显的东西吗?

 <?php

error_reporting (E_ALL ^ E_NOTICE);

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Register Page</title>
</head>

<body>
<?php




if ( $_POST ['registerbtn']) {
  $getuser =$_post ['user'];
  $getemail =$_post ['email'];
  $getpass =$_post ['pass'];
  $getretypepass =$_post ['retypepass'];




    if($getuser){

        if ($getemail){

            if ($getpass){

                if ($getretypepass){

                    if ($getpass === $getretypepass){

                        if ((strlen ($getemail) >=7 ) && (strstr ($getemail, "@")) && (strstr ($getemail, "."))) {
                                require ("./connect.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 ("kjfiufj".$password."Fj56fj"));
                                                            $date("F d, Y");
                                                            $code = md5(rand ());

                                                            mysql_query ("INSERT INTO users VALUES (

                                                            '', '$getuser','$password','$getemail', '0', '$code', '$date')");

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


                                    if ($numrows == 1){

                                                                            $site = "http://www.andyhoole.co.uk";
                                                                            $webmaster = "AndyHoole <admin@andyhoole.co.uk>";
                                                                            $headers = "From: $webmaster";
                                                                            $subject = "Activate your account";
                                                                            $message = " Thank you for registering :) . Clink the link below to activate your account.\n ";
                                                                            $message .="$site/activate.php?user=$getuser&code=$code\n";
                                                                            $message .= "You must activate your account to log in.";

                                        if ( mail($getemail,$subject, $message, $headers) ){

                                                        $errormsg = "You have been registered, you must activate your account form the activation link sent to <b> $getemail </b>";
                                                        $getuser = "";
                                                        $getemail = "";

                                        }else
                                            $errormsg = "An error has occured. Your activation email was not sent.";




                                    }else
                                        $errormsg = " An error has occured and your account has not been created. ";

                                }else
                                    $errormsg = " This email address already exsists.";         

                            }else
                                $errormsg = " This username already exsists.";              

                                        mysql_close();

                        }else
                            $errormsg = "You must enter a valid email address to register.";

                     }else
                        $errormsg = "Your passwords did not match.";

                 }else
                    $errormsg = "You must retype your password to register.";

            }else
                $errormsg = "You must enter your password to register.";

        }else
            $errormsg = "You must enter your email address to register.";
    }else
        $errormsg = "You must enter your User name to register.";


}



$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;


?>

</body>

</html>

谢谢你看:)

4

1 回答 1

1

你也应该使用$_POST,而不是$_post因为 php 区分大小写!

于 2013-03-19T01:16:29.473 回答