Hello all,
I'm a PHP newbie and have my apache Server and PHP in place. I have been able to run simple programs that work well. However, since then when I do "http ://localhost/filename.php" I either get 2 messages.
1. An error message if there's an error in my code
2. A blank page if I don't get an error message.

For example, the code below gives a blank screen. Pls help me with this.

<?php
    $pictures = array('PixsIMG_0037.jpg','PixsIMG_0038.jpg','PixsIMG_0039.jpg
    ','PixsIMG_0040.jpg');

    shuffle($pictures);
    ?> 

 

<html>
<head>
	<title>Doe Cafe</title>
</head>
<body>
  <center>
     <h1>Doe Cafe</h1>
     <table width = '100%' >
      <tr>

    
    <?php
    for( $i = 0; $i < 3; $i++)
     {
         echo '<td align="center"><img src =" ';
        // echo $pictures[$i];
         echo $i;
         echo ' "width ="100" height ="100"></td>;
    }
    <?

  </tr>
  </table>
 </center>
 </body>
</html>

Dani AI

Generated

A blank page in PHP almost always means the interpreter hit a fatal error that the server is configured not to display, or the script produced HTML that the browser doesn't render (for example, malformed attributes or missing image files). already pointed out several syntax problems in the original snippet; the fastest way to make those problems visible is to enable error reporting at runtime and inspect the generated HTML.

<?php
// Temporary debug — place at the very top of the PHP file
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

// Quick check of the array/variables
echo '<pre>';
var_dump($pictures);
echo '</pre>';
// exit; // uncomment to stop the rest of the page while debugging
?>

If those lines produce nothing, the script may be failing before they run (parse error). In that case consult the Apache/PHP error log for an exact message and line number. Common log locations: macOS built-in Apache — /var/log/apache2/error_log; MAMP — /Applications/MAMP/logs/apache_error.log; XAMPP (mac) — /Applications/XAMPP/xamppfiles/logs/error_log; Linux — /var/log/apache2/error.log or /var/log/httpd/error_log; Windows XAMPP/WAMP have similar apache/logs/error files. Changing php.ini (display_errors = On, error_reporting = E_ALL) and restarting Apache also makes server-level debugging easier (as noted).

Missing or incorrect image output is usually an HTML problem rather than PHP: view-source in the browser and use the developer tools Network tab to catch 404s or malformed tags. Watch for stray spaces or quotes inside the src attribute and for case-sensitive filenames on Unix hosts. When inserting filenames into attributes, escape them to avoid breaking HTML:

printf(
  '<td align="center"><img src="%s" width="100" height="100" alt="%s"></td>',
  htmlspecialchars($file, ENT_QUOTES),
  htmlspecialchars($file, ENT_QUOTES)
);

Remove the debugging lines before moving to production. The combination of runtime error display, server error logs, and browser dev tools will reveal the exact syntax or resource errors that produce a blank page. This approach applies whether the environment is Windows, Linux, or the macOS setup mentioned by .

Recommended Answers

All 5 Replies

There is many errors in your PHP statement thats in the body of your page which I will explain below. Try somthing like this:

<?php
 
  for( $i = 0; $i < 4; $i++)
  {
 
    echo "<td align='center'><img src='" . $pictures[$i] . "' width='100' height='100' alt='" . $i . "'></td>";
 
  }
 
?>

Your errors were here:

- Your if statment will only display 3 photos while there is 4 in your array. You can either change the number to test for to 4, or change your tester to less than or equal to .... <=.

- You commented out the part that places the picture filename into the image tag. (the // makes PHP ignore it.)

-You put the value of $i in the src part of your image tag.

- You did not close the third echo after the </td> tag

- Your PHP closing tag is backwards. Should be ?>

There is many errors in your PHP statement thats in the body of your page which I will explain below. Try somthing like this:

<?php
 
  for( $i = 0; $i < 4; $i++)
  {
 
    echo "<td align='center'><img src='" . $pictures[$i] . "' width='100' height='100' alt='" . $i . "'></td>";
 
  }
 
?>

Your errors were here:

- Your if statment will only display 3 photos while there is 4 in your array. You can either change the number to test for to 4, or change your tester to less than or equal to .... <=.

- You commented out the part that places the picture filename into the image tag. (the // makes PHP ignore it.)

-You put the value of $i in the src part of your image tag.

- You did not close the third echo after the </td> tag

- Your PHP closing tag is backwards. Should be ?>

First I want to thank you for pointing out my errors, but I also have a question for you.
How do I see what errors I have with my PHP codes?(I mean is there like something similar to a debug window where errors and / or lines where they are will be displayed for my PHP codes)

Thanks

Member Avatar for Member #117553

First I want to thank you for pointing out my errors, but I also have a question for you.
How do I see what errors I have with my PHP codes?(I mean is there like something similar to a debug window where errors and / or lines where they are will be displayed for my PHP codes)

Thanks

PHP points the erroneus lines in your code, but you have to understand very well the code in order to debug. E.G. there is a difference between things like echo '$var' and echo "$var".

If you want to see errors, you have to modify your php.ini file to show the errors along with the code on the page, or, you can review the apache error log - it contains all errors occured in the PHP code.
Note errors are similar to this :

Error: Unexpected T_VARIABLE , expecting ',' or ';' on line 65 in "C:\php\my_php_file.php"

Does any one know how to see the actual output of a PHP file?
say all the code is right.. now I want to see it displayed in my screen.

It happens that I downloaded a php file from a already made template and would like to see it to then make the changes.. please advice.
Thanks
Enrique

I just submitted a request for assistance; it is important to mention that I am on a MAC OS 10.5.8
Thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.