2015-06-17 26 views
0

當我在瀏覽器中打開它時,PHP文件是空白的。另外,當我打開源代碼時,它也是空的。PHP頁面爲空且源代碼爲空

這是tutorial我下面

這裏是代碼:

<?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 <[email protected]>"; 
             $headers = "From: $webmaster"; 
             $subject = "Activate Your New Account!"; 
             $message = "Thanks for regisntering. Click the link below to activate your account!\n"; 
             $message .= "$site/activate?user=$getuser&code=$code\n"; 
             $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

你錯過了','這個行'$ site =「http:// localhost/PHP Projects/Member System」' – cmorrissey

+0

PHP中的空白頁通常意味着服務器端存在錯誤。打開錯誤報告,檢查日誌等。確定錯誤是什麼。 – David

+0

你如何打開錯誤報告? –

回答

0

你有錯誤就這一行 if (strlen($getemail) >= 7) && (strstr($getemail, "@")) && (strstr($getemail, ".")) {

它必須是if ((strlen($getemail) >= 7) && (strstr($getemail, "@")) && (strstr($getemail, "."))) {

b中的源代碼rowser會告訴你html代碼不是php PHP是服務器端所以它的代碼是在服務器和瀏覽器中無法看到 PHP代碼

全碼

<?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 <[email protected]>"; 
             $headers = "From: $webmaster"; 
             $subject = "Activate Your New Account!"; 
             $message = "Thanks for regisntering. Click the link below to activate your account!\n"; 
             $message .= "$site/activate?user=$getuser&code=$code\n"; 
             $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> 
+0

代碼轉儲答案與代碼轉儲問題一樣糟糕。謹慎解釋你改變了什麼? – Sean

+0

謝謝!這工作。 Stackoverflow FTW! –

+0

對不起,我改變了它 – robert