6

I have a PHP page that I developed locally and worked fine. Upon uploading it to a server I now just get a blank white screen? It is the exact same code, works fine locally but doesnt remotely. I have tried setting on error reporting but that still doesn t give me any errors, just a blank white screen.

The code:

    $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";
        }
        
        
    }
    
desertnaut
  • 57,590
  • 26
  • 140
  • 166
Mikey
  • 345
  • 5
  • 9
  • 15
  • Probably the server is not set properly? – gbestard Apr 07 '14 at 11:50
  • 1
    It's probably a PHP notice - make sure your live php.ini file has display_errors set to on. Alternatively you can do this in the code with ini_set('display_errors', 'on'); – Matt Humphrey Apr 07 '14 at 11:50
  • Put this in your php.ini @ your error repoting line - error_reporting=~E_ALL & ~E_DEPRECATED & ~E_STRICT & ~E_NOTICE & ~WARNING – Sulthan Allaudeen Apr 07 '14 at 11:52
  • I dont think the problem lies with the server as all of the other file display perfectly. I have tried all the error reporting methods but still I get no error messages :( – Mikey Apr 07 '14 at 11:53
  • Seems like `$_SERVER` environment isn't set. Do a `var_dump($_SERVER)` and see what it returns. – Basit Apr 07 '14 at 11:55
  • Did you check your Apache logs? On Ubuntu, look in `/var/logs/apache2/` for either your named server’s specific log or the generic `error.log`? – Giacomo1968 Apr 07 '14 at 11:57
  • Check for `$_SERVER["REQUEST_METHOD"]` and if is not set, check for `isset($_POST)` instead – Sal00m Apr 07 '14 at 12:01
  • I spent ages finding the error causing a blank page, deleted my code row by row but even a hello world didn't work at the end. Turned out I messed up the link to the page and put a ; after ?page=foo. It was too small to see (yeah I'm an old man) Anyway, unlikely that anyone else would make the same mistake but you never know. – Szél Lajos Jan 22 '23 at 10:18

4 Answers4

10

This will enable showing errors in your server, but remember, isn't recommended to use this in production and not in a PHP file, these configuration must be setted in php.ini

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

For further information you can see:

Alfredo Costa
  • 416
  • 3
  • 21
0

Things to check:

  • $_SERVER["REQUEST_METHOD"]: If you are using another server, this could be the problem, check if this key exists, else, use isset($_POST) instead

  • Database connection?, perhaps some errors with user or pass?

  • Check PHP error logs, if you don't know where are stored then execute this: php -i | grep error_log, should return the path to error log

  • Check server error logs, the logs normally are in /var/log/SERVER (SERVER could be lighttpd, apache, nginx, httpd,... it depends)

Alternatively you can use the ini_set directive and activate error_reporting

Sal00m
  • 2,938
  • 3
  • 22
  • 33
-1

A Blank white screen happens when you don't have installed the PHP on your server or may be using a different version of PHP than what you wrote your code in. so check your PHP version by typing on the command line php -v.

Rizvi21
  • 1
  • 1
-2

It means process finished. Everything is fine code has ended no error.

You should do like echo 'You have successfully created'.

Abhinash Majhi
  • 499
  • 1
  • 4
  • 16