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>

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 Rhyan

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.