开发者

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.


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>)


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


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>


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.


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);


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.


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜