簡體   English   中英

PHP空白白頁,沒有錯誤

[英]PHP blank white page, no errors

我有一個我在本地開發的 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";
        }
        
        
    }
    

這將允許在您的服務器中顯示錯誤,但請記住,不建議在生產中使用它而不是在 PHP 文件中使用它,這些配置必須在 php.ini 中設置

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

有關更多信息,您可以查看:

檢查事項:

  • $_SERVER["REQUEST_METHOD"] :如果您使用的是另一台服務器,這可能是問題所在,請檢查此密鑰是否存在,否則,請改用isset($_POST)

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

  • 檢查 PHP 錯誤日志,如果您不知道存儲在哪里,請執行以下操作: php -i | grep error_log php -i | grep error_log ,應該返回錯誤日志的路徑

  • 檢查服務器錯誤日志,日志通常在/var/log/SERVER (服務器可能是 lighttpd、apache、nginx、httpd……這取決於)

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

我有一個在本地開發的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";
        }


    }

這意味着過程完成。 一切都很好,代碼結束沒有錯誤。

你應該像echo 'You have successfully created'

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM