Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Jan 2010
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How to avoid this error message?

    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:

    PHP Code:
                <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?

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    You can probably do something like
    PHP Code:
    <?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?
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #3
    New Coder
    Join Date
    Jan 2010
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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
    Last edited by partisanentity; 01-07-2010 at 12:12 AM.

  • #4
    Regular Coder
    Join Date
    Jan 2007
    Posts
    217
    Thanks
    9
    Thanked 0 Times in 0 Posts
    By defining, he means are you actually using it. i.e.

    $content .="some html here";

  • #5
    Regular Coder
    Join Date
    Dec 2009
    Location
    Hong Kong
    Posts
    119
    Thanks
    8
    Thanked 0 Times in 0 Posts
    I include() usually files, such as:

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

    //  this also works:

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


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

  • #6
    met
    met is offline
    Regular Coder
    Join Date
    Oct 2009
    Location
    United Kingdom
    Posts
    728
    Thanks
    4
    Thanked 119 Times in 119 Posts
    PHP Code:
         <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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •