2014-04-07 102 views
4

我有一個我在本地開發的PHP頁面,工作正常。將它上傳到服務器後,我現在只是看到一個空白的白屏?它是完全相同的代碼,在本地很好地工作,但遠程沒有。我試圖設置錯誤報告,但仍然沒有給我任何錯誤,只是一個空白的白屏。PHP空白頁面,沒有錯誤

編輯----------代碼:

$firstname = $phone = $email = $picture = $sqlcon = ""; 
    $firstnameErr = $phoneErr = $emailErr = $pictureErr = $sqlErr = $filterErr = ""; 
    $statusmsg = ""; 
    $newpicture = $registered = "false"; 

    if ($_SERVER["REQUEST_METHOD"] == "POST") { 

     // If the user has not entered a firstname and has not entered details previously 
     if ((empty($_POST["firstname"])) && empty($_POST["hfirst"])) { 

      $firstnameErr = "Firstname is required for submission"; 
     } 
     else { 

      if (!empty($_POST["firstname"])) { 

       $firstname = $_POST["firstname"]; 
      } 
      else { 

       $firstname = $_POST["hfirst"]; 
      } 

      if (!preg_match("/^[a-zA-Z ]*$/", $firstname)) { 

       $firstnameErr="Please ensure you have entered only characters for your first name"; 
      } 
     } 

     // If the user has not entered a phone number and has not entered details previously 
     if ((empty($_POST["phone"])) && (empty($_POST["hphone"]))) { 

      $phoneErr = "Please ensure you have entered a phone number"; 
     } 
     else { 

      if (!empty($_POST["phone"])) { 

       $phone = $_POST["phone"]; 
      } 
      else { 

       $phone = $_POST["hphone"]; 
      } 

      if (!is_numeric($phone)) { 

       $phoneErr = "Please ensure you have entered a valid phone number"; 
      } 
     } 

     if ((empty($_POST["email"])) && (empty($_POST["hemail"]))) { 

      $emailErr = "Please ensure you have entered your email address"; 
     } 
     else { 

      if (!empty($_POST["email"])) { 

       $email = $_POST["email"]; 
      } 
      else { 

       $email = $_POST["hemail"]; 
      } 

      if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email)) { 

       $emailErr = "Please ensure you have entered a valid email address"; 
      } 
     } 

     if ((empty($_FILES["file"]["name"])) && (empty($_POST["hfile"]))) { 

      $pictureErr = "Please ensure you have selected a picture to upload"; 
     } 
     else { 

      if (!empty($_FILES["file"]["name"])) { 

       if ($_FILES["file"]["size"] > 1048576) { 

         $pictureErr = "The maximum size for a picture is 1mb"; 
       } 
       else { 

        // Ensure the user has selected a file of accepted type 
        $temp = explode(".", $_FILES["file"]["name"]); 
        $ext = end($temp); 
        $allowedExt = array ("gif", "JPEG", "jpg", "png", "JPG"); 

        if (!in_array($ext, $allowedExt)) { 

         $pictureErr = "Please ensure you have uploaded an image file";        

        } 
       } 

       $newpicture = "true"; 
       $picture = $_FILES["file"]["name"]; 

      } 
      else { 

       $picture = $_POST["hpicture"]; 
      } 
     } 

     $sqlcon = mysqli_connect("localhost", "USER", "PASS", "personneldb"); 

     if (mysqli_connect_errno()) { 

      $sqlErr = "Could not connect to database"; 
      mysqli_close($sqlcon); 
     } 

     if ($newpicture == "true") { 

      if (!move_uploaded_file($_FILES["file"]["tmp_name"], "./upload/".$_FILES["file"]["name"])) { 

       $pictureErr = "File could not be uploaded"; 
      } 
     } 

     if ((empty($firstnameErr)) && (empty($emailErr)) && (empty($phoneErr)) && (empty($pictureErr == "")) && (empty($sqlErr == ""))) { 

      mysqli_query($sqlcon, "INSERT INTO test2Details(Firstname, Phone, Email, ImageName) 
      VALUES ('$firstname', '$phone', '$email', '$picture')"); 

      // Display status message 
      $statusmsg = "Success! Your details and picture have been uploaded and stored"; 


     } 

     if ((!empty($firstname)) && (!empty($phone)) && (!empty($email)) && (!empty($picture))) { 

      $registered = "true"; 
     } 
     else { 

      $registered = "false"; 
     } 


    } 
+2

向我們展示您的PHP代碼 – Albzi

+0

可能是服務器設置不正確? – gbestard

+1

這可能是一個PHP通知 - 確保你的php.ini文件的display_errors設置爲on。或者,您可以在代碼中使用ini_set('display_errors','on')執行此操作; –

回答

6

這將使顯示在你的服務器錯誤,但要記住,不建議在生產和不使用這個在PHP文件,這些配置必須在php.ini

ini_set('display_startup_errors',1); 
ini_set('display_errors',1); 
error_reporting(-1); 

欲瞭解更多信息,可以設置好的,你可以看到:

+1

在服務器上的php.ini文件中?我沒有訪問該文件 – Mikey

+0

不,你可以把它放在你的PHP文件 – Sal00m

+0

@EduardoVerdugoCáceres是的,你可以。推薦的 –

0

檢查事項:

  • $_SERVER["REQUEST_METHOD"]:如果您使用另一臺服務器,這可能是問題,檢查這個鍵存在,否則,使用isset($_POST)改爲

  • 數據庫連接?,或許與用戶或通過一些錯誤?

  • 檢查PHP錯誤日誌,如果你不知道在哪裏存儲然後執行此:php -i | grep error_log,應該返回到錯誤日誌

  • 檢查服務器錯誤日誌的路徑,日誌通常是/var/log/SERVER(SERVER可能是lighttpd的,阿帕奇,Nginx的,httpd的,......這取決於)

或者您可以使用的ini_set指令並激活error_reporting

0

設法解決我的問題,得到了服務器上的錯誤日誌,發現我得到一個解析錯誤!