943,576 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 7887
  • PHP RSS
Feb 18th, 2007
0

Display output on webpage

Expand Post »
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 Syntax (Toggle Plain Text)
  1. <?php
  2. $pictures = array('PixsIMG_0037.jpg','PixsIMG_0038.jpg','PixsIMG_0039.jpg
  3. ','PixsIMG_0040.jpg');
  4.  
  5. shuffle($pictures);
  6. ?>
  7.  
  8.  
  9.  
  10. <html>
  11. <head>
  12. <title>Doe Cafe</title>
  13. </head>
  14. <body>
  15. <center>
  16. <h1>Doe Cafe</h1>
  17. <table width = '100%' >
  18. <tr>
  19.  
  20.  
  21. <?php
  22. for( $i = 0; $i < 3; $i++)
  23. {
  24. echo '<td align="center"><img src =" ';
  25. // echo $pictures[$i];
  26. echo $i;
  27. echo ' "width ="100" height ="100"></td>;
  28. }
  29. <?
  30.  
  31. </tr>
  32. </table>
  33. </center>
  34. </body>
  35. </html>
  36.  
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
crestaldin is offline Offline
30 posts
since Mar 2005
Feb 19th, 2007
0

Re: Display output on webpage

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 Syntax (Toggle Plain Text)
  1.  
  2. <?php
  3.  
  4. for( $i = 0; $i < 4; $i++)
  5. {
  6.  
  7. echo "<td align='center'><img src='" . $pictures[$i] . "' width='100' height='100' alt='" . $i . "'></td>";
  8.  
  9. }
  10.  
  11. ?>

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 ?>
Last edited by GliderPilot; Feb 19th, 2007 at 5:10 pm.
Reputation Points: 8
Solved Threads: 2
Junior Poster in Training
GliderPilot is offline Offline
57 posts
since Sep 2006
Feb 23rd, 2007
0

Re: Display output on webpage

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 Syntax (Toggle Plain Text)
  1.  
  2. <?php
  3.  
  4. for( $i = 0; $i < 4; $i++)
  5. {
  6.  
  7. echo "<td align='center'><img src='" . $pictures[$i] . "' width='100' height='100' alt='" . $i . "'></td>";
  8.  
  9. }
  10.  
  11. ?>

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
Reputation Points: 10
Solved Threads: 0
Light Poster
crestaldin is offline Offline
30 posts
since Mar 2005
Feb 28th, 2007
0

Re: Display output on webpage

Click to Expand / Collapse  Quote originally posted by crestaldin ...
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"
Reputation Points: 21
Solved Threads: 26
Posting Whiz in Training
Rhyan is offline Offline
240 posts
since Oct 2006
Jan 11th, 2012
0

Seeking help with 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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
smash95608 is offline Offline
2 posts
since Jan 2012
Jan 11th, 2012
0

Adding some more to my previous post.

I just submitted a request for assistance; it is important to mention that I am on a MAC OS 10.5.8
Thanks
Reputation Points: 10
Solved Threads: 0
Newbie Poster
smash95608 is offline Offline
2 posts
since Jan 2012
Message:
Previous Thread in PHP Forum Timeline: PHP Keylogger Script
Next Thread in PHP Forum Timeline: Looped Form to save in Same page





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC