...

View Full Version : How to avoid this error message?



partisanentity
01-06-2010, 10:53 PM
I hope I can explain this properly.

For a school project I am working on developing a simple web CMS. I have most of it up and running.

I have a php file called contentarea.php that contains the following:


<div id="contentarea">
<div class="content">
<?php include ($content); ?>
</div>
</div>

All output and the content of other pages is sent to $content.

But until this happens, sometimes $content contains nothing and I get this error:

Notice: Undefined variable: content in /Applications/MAMP/htdocs/main/contentarea.php on line 4

Warning: include() [function.include]: Filename cannot be empty in /Applications/MAMP/htdocs/main/contentarea.php on line 4

Warning: include() [function.include]: Failed opening '' for inclusion (include_path='.:/Applications/MAMP/bin/php5/lib/php') in /Applications/MAMP/htdocs/modcars/contentarea.php on line 4

What can I do to get rid of this warning?

_Aerospace_Eng_
01-06-2010, 11:06 PM
You can probably do something like

<?php if(isset($content)) include($content); ?>
although the notice you are getting though means the $content variable doesn't even exist. Is it defined anywhere?

partisanentity
01-06-2010, 11:10 PM
Thanks for the quick reply.

Not it's not defined anywhere, I was worried that if I define it, then my content would not show up there anymore.

What would be the best way to define it ?

edit: okay using your if clause seems to have solved it, no more errors or notices. thanks

ole90
01-07-2010, 01:49 AM
By defining, he means are you actually using it. i.e.

$content .="some html here";

fail
01-07-2010, 07:01 AM
I include() usually files, such as:



<?php
include("/css/cssmenu.php");
include("/css/connect.php");
?>

// this also works:

<?php
$connect = "/css/cssmenu.php";


include("$connect");
include("/css/connect.php");
?>

met
01-07-2010, 09:50 AM
<div id="contentarea">
<div class="content">
<?php include ($content); ?>
</div>
</div>



what does $content contain

include() expects a valid file - if $content is just HTML etc it won't output anything.

use echo instead, for instance.

edit: see you've fixed it now, disregard.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum