dsa89029 2015-06-17 19:03
浏览 38
已采纳

PHP页面是空白的,源代码是空的

The PHP file is blank when I open it up in the browser. Also, when I open the source code, it is empty as well.

This is the tutorial I am following

And here is the code:

<?php

error_reporting(E_ALL ^ E_NOTICE);

?>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Member System - Register</title>
</head>
<body>
<?php

if ($_POST['registerbtn']) {
    $getuser = $_POST['user'];
    $getemail = $_POST['email'];
    $getpass = $_POST['pass'];
    $getconfirmpass = $_POST['confirmpass'];

    if ($getuser) {
        if ($getemail) {
            if ($getpass) {
                if ($getconfirmpass) {
                    if ($getpass === $getconfirmpass) {
                        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".$getpass."Fjf56fj"));
                                    $date = 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://localhost/PHP Projects/Member System";
                                        $webmaster = "Askman <donotreply@askmanproducts.com>";
                                        $headers = "From: $webmaster";
                                        $subject = "Activate Your New Account!";
                                        $message = "Thanks for regisntering. Click the link below to activate your account!
";
                                        $message .= "$site/activate?user=$getuser&code=$code
";
                                        $message .= "You must activate your account to login.";

                                        if (mail($getemail, $subject, $message, $headers)){
                                            $errormsg = "You have been registered. You must activate your account from 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. Your account was not created.";

                                }
                                else
                                    $errormsg = "There is already a user with that email.";
                            }
                            else
                                $errormsg = "There is already a user with that username.";

                            mysql_close();
                        }
                        else
                            $errormsg = "You must enter a valid email address to register.";
                    }
                    else
                        $errormsg = "Your passwords did not match.";
                }
                else 
                    $errormsg = "You must confirm your password to register.";
            }
            else
                $errormsg = "You must enter your password to register.";
        }
        else
            $errormsg = "You must enter your email to register.";
    }
    else 
        $errormsg = "You must enter your username to register.";

}

$form = "<form action='./register' 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>Confirm Password:</td>
    <td><input type='password' name='confirmpass' value='' /></td>
</tr>
<tr>
    <td></td>
    <td><input type='submit' name='registerbtn' value='Register' /></td>
</tr>
</table>
</form>";

echo $form;

?>
</body>
</html>
  • 写回答

1条回答 默认 最新

  • doupu2722 2015-06-17 19:12
    关注

    you have error on this line if (strlen($getemail) >= 7) && (strstr($getemail, "@")) && (strstr($getemail, ".")) {

    it must be if ((strlen($getemail) >= 7) && (strstr($getemail, "@")) && (strstr($getemail, "."))) {

    alse the source code in the browser will show you the html code not the php php is server side so it's code is inside the server and browser can not see the php code

    full code

    <?php
    
    error_reporting(E_ALL ^ E_NOTICE);
    
    ?>
    <!DOCTYPE html>
    <html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Member System - Register</title>
    </head>
    <body>
    <?php
    
    if ($_POST['registerbtn']) {
        $getuser = $_POST['user'];
        $getemail = $_POST['email'];
        $getpass = $_POST['pass'];
        $getconfirmpass = $_POST['confirmpass'];
    
        if ($getuser) {
            if ($getemail) {
                if ($getpass) {
                    if ($getconfirmpass) {
                        if ($getpass === $getconfirmpass) {
                            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".$getpass."Fjf56fj"));
                                        $date = 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://localhost/PHP Projects/Member System";
                                            $webmaster = "Askman <donotreply@askmanproducts.com>";
                                            $headers = "From: $webmaster";
                                            $subject = "Activate Your New Account!";
                                            $message = "Thanks for regisntering. Click the link below to activate your account!
    ";
                                            $message .= "$site/activate?user=$getuser&code=$code
    ";
                                            $message .= "You must activate your account to login.";
    
                                            if (mail($getemail, $subject, $message, $headers)){
                                                $errormsg = "You have been registered. You must activate your account from 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. Your account was not created.";
    
                                    }
                                    else
                                        $errormsg = "There is already a user with that email.";
                                }
                                else
                                    $errormsg = "There is already a user with that username.";
    
                                mysql_close();
                            }
                            else
                                $errormsg = "You must enter a valid email address to register.";
                        }
                        else
                            $errormsg = "Your passwords did not match.";
                    }
                    else
                        $errormsg = "You must confirm your password to register.";
                }
                else
                    $errormsg = "You must enter your password to register.";
            }
            else
                $errormsg = "You must enter your email to register.";
        }
        else
            $errormsg = "You must enter your username to register.";
    
    }
    
    $form = "<form action='./register' 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>Confirm Password:</td>
        <td><input type='password' name='confirmpass' value='' /></td>
    </tr>
    <tr>
        <td></td>
        <td><input type='submit' name='registerbtn' value='Register' /></td>
    </tr>
    </table>
    </form>";
    
    echo $form;
    
    ?>
    </body>
    </html>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?