vorbb
vorbb

Reputation: 31

Simple PHP Code; Blank Screen?

I'm just starting to learn PHP. I have a friend who's fairly good at it, and had him look at my code, and he couldn't see anything wrong with it, and said I should try here.

Basically, I was just playing around and wanted to make a simple "to-do" list.

Here is the code for my index.php file:

<html>
<title>
Tasks
</title>
<body>

<?php

echo "I have so many tasks to do...";
<br>
<br>
include("tasks.php"); 
?>

<br>

<br>


</body>
</html>

And, finally, my tasks.php file:

<ol>

<li> 1. Wow.
<li> 2. Cool.
<li> 4. Oops.

</ol>

It seems to me like it should be working, but all I get is a white screen. If I take out the include statement, I get the echo statement fine, so I think it must be something wrong with the include statement. Also, I have made sure that the index.php and tasks.php file are in the same directory.

Thank you all so much for your help.

Upvotes: 1

Views: 1946

Answers (8)

Sarfraz
Sarfraz

Reputation: 382909

Problem is that you have mixed <br> tags in php code:

<?php
echo "I have so many tasks to do...";
<br> // <-- Wrong
<br> // <-- Wrong
include("tasks.php"); 
?>

Should be:

<?php
echo "I have so many tasks to do...";
?>
<br />
<br />
<?php
include("tasks.php"); 
?>

Or:

<?php
echo "I have so many tasks to do...";
echo '<br />';
echo '<br />';
include("tasks.php"); 
?>

You have also not written closing tags for li:

<ol>

<li> 1. Wow.
<li> 2. Cool.
<li> 4. Oops.

</ol>

Should be:

<ol>
  <li> 1. Wow. </li>
  <li> 2. Cool. </li>
  <li> 4. Oops. </li>
</ol>

Note: To get error messages/description on your screen rather than blank window, put these two lines on top of your script:

ini_set('display_errors', true);
error_reporting(E_ALL);

Upvotes: 1

Shoe
Shoe

Reputation: 76298

There are 2 errors:

1- <br> cannot be inserted into <?php ?> tags. It is an html tag that must be out of the php code or inside a string. So close the <?php with ?> before <br> and re open them before the include as already pointed out.

2- <li> tags must be closed with </li> but that is not the meaning of the blank page.

The page is blank due to the parse error the php compiler output because of the two "
". It seems that you have your error_reporting(0) to 0. Please set on the top of your page the following code:

error_reporting(E_ALL);

So that you will be able to output error messages and fix them.

Upvotes: 1

Dai
Dai

Reputation: 1510

To summarise what you have been told:

<html>
<title>
Tasks
</title>
<body>
<?php
echo "I have so many tasks to do...";
?>
<br>
<br>
<?php
include("tasks.php"); 
?>
<br>
<br>
</body>
</html>

Should be your main and:

<ol>

<li> 1. Wow. </li>
<li> 2. Cool. </li>
<li> 4. Oops. </li>

</ol>

Should be tasks.php

Upvotes: 0

Svisstack
Svisstack

Reputation: 16656

Add error_reporting(E_ALL) on the top of script, then you will know what is wrong.

Upvotes: 2

Teson
Teson

Reputation: 6736

blank screen probably means You're using production server error-reporting, try

error_reporting(E_ALL ^ E_NOTICE);

on first row after the open-php-tag

Upvotes: 0

Ondrej Slint&#225;k
Ondrej Slint&#225;k

Reputation: 31970

You use <br> tags inside of PHP script which isn't permitted. You'll have to change

<?php

echo "I have so many tasks to do...";
<br>
<br>
include("tasks.php"); 
?>

into

<?php

echo "I have so many tasks to do...";
?>

<br>
<br>

<?php
include("tasks.php"); 
?>

Eventually you could also put <br> tags inside of your echo:

<?php

echo "I have so many tasks to do...<br /><br />";

include("tasks.php"); 
?>

which would have the same effect.

Upvotes: 0

Sean Delaney
Sean Delaney

Reputation: 11

You've not included the break line tags
correctly inside your PHP:

<html>
<title>
Tasks
</title>
<body>

<?php

echo "I have so many tasks to do...<br><br>";

include("tasks.php"); 
?>

<br>

<br>


</body>
</html>

Upvotes: 1

oezi
oezi

Reputation: 51817

change

<?php

echo "I have so many tasks to do...";
<br>
<br>
include("tasks.php"); 
?>

to

<?php
echo "I have so many tasks to do...";
?>
<br />
<br />
<?php
include("tasks.php"); 
?>

PS: you should realy try to write correct html - you havn't closed you li-elements and you havn't written the br as empty element (<br />, not <br>)

Upvotes: 4

Related Questions