My PHP Page Loaded All White. What Did I Do Wrong?

Tips for preventing and troubleshooting all white or blank PHP web pages

Businesswoman working on the computer
Nenad Aksic/E+/Getty Images

You upload your PHP web page and go to view it. Instead of seeing what you expected, you see nothing. A blank screen (often white), no data, no error, no title, nothing. You view the source ... it's blank. What happened?

Missing Code

The most common reason for a blank page is that the script is missing a character. If you left out a ' or } or ; somewhere, your PHP won't work. You don't get an error; you just get a blank screen.

There is nothing more frustrating than looking through thousands of lines of code for the one missing semicolon that is messing the whole thing up. What can be done to correct and prevent this from happening.

  • Turn on PHP Error Reporting. You can learn a lot about what is going wrong from the error messages PHP gives you. If you aren't currently getting error messages, you should turn on PHP error reporting.
  • Test your code often. If you test each piece as you add it, then when you encounter a problem, you know the specific section to troubleshoot. It'll be in whatever you just added or changed.
  • Try a color-coded editor. A lot of PHP editors—even free ones—color code your PHP as you enter it. This helps you pick out lines that don't end because you'll have large chunks of code in the same color. It's non-intrusive for programmers who prefer to code with no bells and whistles but helpful when troubleshooting.
  • Comment it out. One way to isolate the problem is to comment out large chunks of your code. Start at the top and comment out all but the first couple of lines in a large block. Then echo () a test message for the section. If it echoes fine, the problem is in a section further down in the code. Move the start of your comment and your test echo downward as you work through your document, until you find the problem.

    Is Your Site Uses Loops

    If you use loops in your code,  it could be that your page is stuck in a loop that never stops loading. You may have forgotten to add ++  to the counter at the end of a loop, so the loop continues to run forever. You may have added it to the counter but then accidently overwritten it at the start of the next loop, so you never gain any ground. 

    One way to help you spot this is to echo() the current counter number or other useful information at the beginning of each cycle. This way you might get a better idea of where the loop is tripping up.

    If Your Site Doesn't Use Loops

    Check that any HTML or Java you use on your page isn't causing a problem and that any included pages are without error.

    Format
    mla apa chicago
    Your Citation
    Bradley, Angela. "My PHP Page Loaded All White. What Did I Do Wrong?" ThoughtCo, Nov. 22, 2016, thoughtco.com/my-page-has-loaded-all-white-2694199. Bradley, Angela. (2016, November 22). My PHP Page Loaded All White. What Did I Do Wrong? Retrieved from https://www.thoughtco.com/my-page-has-loaded-all-white-2694199 Bradley, Angela. "My PHP Page Loaded All White. What Did I Do Wrong?" ThoughtCo. https://www.thoughtco.com/my-page-has-loaded-all-white-2694199 (accessed January 21, 2018).