SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Member
    Join Date
    May 2007
    Location
    Peterborough, UK
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Include within an echo statement doesn't work

    I cannot get the following code to work.

    <?php
    if(date("Ymd")<"20070928")
    {
    echo "
    <tr>
    <td class='diary' width='12%'>Fri<br>28<br>September<br>2007</td>
    <td class='diary' width='12%' >7.15 pm </td>
    <td class='diary' width='25%' >Annual Dinner </td>
    <td class='diary' width='25%' >" . include $_SERVER['DOCUMENT_ROOT'] . '/includes/marsh.inc.php' . "</td>
    <td class='diary' width='24%'><a class='diary' href='mailto:judyzz@geraldc.co.uk?subject=Annual_Dinner_2007'>Judy</a> on 01234 567890 </td>
    </tr>";
    }
    ?>

    It produces the following message : Warning: main(/home/fhlinux186/x/xoopytester.co.uk/user/htdocs/includes/marsh.inc.php</td> <td class='diary' width='24%'><a class='diary' href='mailto:judyzz@fitzgeraldc.co.uk?subject=Annual Dinner 2007'>Judy</a> on 01234 567890 </td> </tr> ) [function.main]: failed to open stream: No such file or directory in /home/fhlinux186/x/xoopytester.co.uk/user/htdocs/diary.php on line 94

    Warning: main(/home/fhlinux186/x/xoopytester.co.uk/user/htdocs/includes/marsh.inc.php</td> <td class='diary' width='24%'><a class='diary' href='mailto:judith@geraldc.co.uk?subject=Annual Dinner 2007'>Judy</a> on 01234 567890 </td> </tr> ) [function.main]: failed to open stream: No such file or directory in /home/fhlinux186/x/xoopytester.co.uk/user/htdocs/diary.php on line 94

    Warning: main() [function.include]: Failed opening '/home/fhlinux186/x/xoopytester.co.uk/user/htdocs/includes/marsh.inc.php</td> <td class='diary' width='24%'><a class='diary' href='mailto:judyzz@geraldc.co.uk?subject=Annual Dinner 2007'>Judy</a> on 01234 567890 </td> </tr> ' for inclusion (include_path='.:/usr/share/pear') in /home/fhlinux186/x/xoopytester.co.uk/user/htdocs/diary.php on line 94

    The include file is present on the remote server and there are no case sesitivity issues. The content of marsh.inc.php is as follows :

    <? php
    {
    echo "<a class='diary' href='http://maps.google.co.uk/maps?f=q&hl=en&geocode=&q=nr1+3qq&ie=UTF8&ll=52.623842,1.291645&spn=0.005901,0.014462&z=16&om=1'>Marsh Ltd</a>";
    }
    ?>

    I have also tried it as :

    <a class='diary' href='http://maps.google.co.uk/maps?f=q&hl=en&geocode=&q=nr1+3qq&ie=UTF8&ll=52.623842,1.291645&spn=0.005901,0.014462&z=16&om=1'>Marsh Ltd</a>

    and

    "<a class='diary' href='http://maps.google.co.uk/maps?f=q&hl=en&geocode=&q=nr1+3qq&ie=UTF8&ll=52.623842,1.291645&spn=0.005901,0.014462&z=16&om=1'>Marsh Ltd</a>"

    The server is on a hosted package.

    Any help would be much appreciated.

  2. #2
    SitePoint Addict jpease's Avatar
    Join Date
    Jul 2002
    Location
    In the network.
    Posts
    217
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Tony718s View Post
    I cannot get the following code to work.

    ...

    include $_SERVER['DOCUMENT_ROOT'] . '/includes/marsh.inc.php'

    ...
    You might try re-writing that as:
    Code:
    include($_SERVER['DOCUMENT_ROOT'] . '/includes/marsh.inc.php')
    Not sure if that is the problem, but might be a good start. I find using parentheses to be very explicit helps solve some problems of this sort.

  3. #3
    SitePoint Member
    Join Date
    May 2007
    Location
    Peterborough, UK
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Include within an echo staement doesn't work

    Jpease

    Thanks for your input. Unfortunately, it hasn't resolved the problem.

    Well worth a try through.

    Kind regards

    Tony

  4. #4
    SitePoint Addict jpease's Avatar
    Join Date
    Jul 2002
    Location
    In the network.
    Posts
    217
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can you post the code now that you adjusted it as I recommended, and the warnings that are being generated?

    It really seems as though it is a error with your include statement according to the warning message. To me it looks like the include is trying to load a file called:

    Quote Originally Posted by Tony718s View Post
    "/home/fhlinux186/x/xoopytester.co.uk/user/htdocs/includes/marsh.inc.php</td> <td class='diary' width='24%'><a class='diary' href='mailto:judyzz@fitzgeraldc.co.uk?subject=Annual Dinner 2007'>Judy</a> on 01234 567890 </td> </tr>"
    Which of course it won't be able to find.

  5. #5
    SitePoint Addict
    Join Date
    Oct 2003
    Location
    United States
    Posts
    281
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Don't echo the include....

    echo "some stuff";
    include("file.php");
    echo "yeah";

  6. #6
    SitePoint Addict jpease's Avatar
    Join Date
    Jul 2002
    Location
    In the network.
    Posts
    217
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by tmapm View Post
    Don't echo the include....

    echo "some stuff";
    include("file.php");
    echo "yeah";
    That's how I'd write it too... but...

    to specifically answer the original question, you need to do this:

    Code:
    <?php
          if(date("Ymd")<"20070928")
          {
          echo "
       <tr>
         <td class='diary' width='12&#37;'>Fri<br>28<br>September<br>2007</td>
         <td class='diary' width='12%' >7.15 pm </td>
         <td class='diary' width='25%' >Annual Dinner </td>
         <td class='diary' width='25%' >" . eval(include($_SERVER['DOCUMENT_ROOT'] . '/includes/marsh.inc.php')). "</td>
    <td class='diary' width='24%'><a class='diary' href='mailto:judyzz@geraldc.co.uk?subject=Annual_Dinner_2007'>Judy</a> on 01234 567890 </td>
       </tr>";
    }
    ?>
    You need the eval() in there to make it work.

  7. #7
    SitePoint Enthusiast
    Join Date
    Oct 2005
    Posts
    96
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Maybe you can try:
    PHP Code:
    <?php
    if(date("Ymd")<"20070928")
    {
    ?>
      <tr>
      <td class='diary' width='12%'>Fri<br>28<br>September<br>2007</td>
      <td class='diary' width='12%' >7.15 pm </td>
      <td class='diary' width='25%' >Annual Dinner </td>
      <td class='diary' width='25%' >
        <?php  include $_SERVER['DOCUMENT_ROOT'] . '/includes/marsh.inc.php' ?>
      </td>
      <td class='diary' width='24%'><a class='diary' href='mailto:judyzz@geraldc.co.uk?subject=Annual_Dinner_2007'>Judy</a> on 01234 567890 </td>
      </tr>
    <?php
    }
    ?>
    OR:

    PHP Code:
    <?php
    if(date("Ymd")<"20070928")
    {
    echo 
    "
    <tr>
    <td class='diary' width='12%'>Fri<br>28<br>September<br>2007</td>
    <td class='diary' width='12%' >7.15 pm </td>
    <td class='diary' width='25%' >Annual Dinner </td>
    <td class='diary' width='25%' >"
    ;
    include 
    $_SERVER['DOCUMENT_ROOT'] . '/includes/marsh.inc.php';
    echo 
    "</td>
    <td class='diary' width='24%'><a class='diary' href='mailto:judyzz@geraldc.co.uk?subject=Annual_Dinner_2007'>Judy</a> on 01234 567890 </td>
    </tr>"
    ;
    }
    ?>

  8. #8
    SitePoint Member
    Join Date
    May 2007
    Location
    Peterborough, UK
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Justin

    Once again, thanks for your time. I can see what you're saying. It's taking the whole code as the include file name. Somehow, the include statement is not terminating.

    Code is as follows :

    <?php
    if(date("Ymd")<"20070928")
    {
    echo "
    <tr>
    <td class='diary' width='12%'>Fri<br>28<br>September<br>2007</td>
    <td class='diary' width='12%' >7.15 pm </td>
    <td class='diary' width='25%' >Annual Dinner </td>
    <td class='diary' width='25%' >" . include ($_SERVER['DOCUMENT_ROOT'] . '/includes/marsh.inc.php') . "</td>
    <td class='diary' width='24%'><a class='diary' href='mailto:judyzz@geraldc.co.uk?subject=Annual_Dinner_2007'>Judith Little</a> on 01234 567890 </td>
    </tr>";
    }
    ?>

    and the error message is :

    Warning: main(/home/fhlinux186/x/xoopytester.co.uk/user/htdocs/includes/marsh.inc.php</td> <td class='diary' width='24%'><a class='diary' href='mailto:judyzz@geraldc.co.uk?subject=Annual_Dinner_2007'>Judith Little</a> on 01234 567890 </td> </tr>) [function.main]: failed to open stream: No such file or directory in /home/fhlinux186/x/xoopytester.co.uk/user/htdocs/diary.php on line 92

    Warning: main(/home/fhlinux186/x/xoopytester.co.uk/user/htdocs/includes/marsh.inc.php</td> <td class='diary' width='24%'><a class='diary' href='mailto:judyzz@geraldc.co.uk?subject=Annual_Dinner_2007'>Judith Little</a> on 01234 567890 </td> </tr>) [function.main]: failed to open stream: No such file or directory in /home/fhlinux186/x/xoopytester.co.uk/user/htdocs/diary.php on line 92

    Warning: main() [function.include]: Failed opening '/home/fhlinux186/x/xoopytester.co.uk/user/htdocs/includes/marsh.inc.php</td> <td class='diary' width='24%'><a class='diary' href='mailto:judyzz@geraldc.co.uk?subject=Annual_Dinner_2007'>Judith Little</a> on 01234 567890 </td> </tr>' for inclusion (include_path='.:/usr/share/pear') in /home/fhlinux186/x/xoopytester.co.uk/user/htdocs/diary.php on line 92

    Line 92, incidentally, is the </tr>"; row which is further indication that the include is taking the rest of the HTML with it.

    Kind regards

    Tony

  9. #9
    SitePoint Member
    Join Date
    May 2007
    Location
    Peterborough, UK
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Include within an echo statement doesn't work

    Thanks guys !! I'm there.

    Code that worked is as follows :

    <?php
    if(date("Ymd")<"20070928")
    {
    echo "
    <tr>
    <td class='diary' width='12%'>Fri<br>28<br>September<br>2007</td>
    <td class='diary' width='12%' >7.15 pm </td>
    <td class='diary' width='25%' >Annual Dinner </td>
    <td class='diary' width='25%' >"; include ($_SERVER['DOCUMENT_ROOT'] . '/includes/marsh.inc.php'); echo "</td>
    <td class='diary' width='24%'><a class='diary' href='mailto:judyzz@geraldc.co.uk?subject=Annual_Dinner_2007'>Judith Little</a> on 01234 567890 </td>
    </tr>";
    }
    ?>

    Kind regards

    Tony

  10. #10
    SitePoint Addict jpease's Avatar
    Join Date
    Jul 2002
    Location
    In the network.
    Posts
    217
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Tony:

    Glad you got it working. I would suggest that you write is like this though:

    Code PHP:
     
       <?php if(date("Ymd")<"20070928"){ ?>
    <tr>
    <td class='diary' width='12%'>Fri<br>28<br>September<br>2007</td>
    <td class='diary' width='12%' >7.15 pm </td>
    <td class='diary' width='25%' >Annual Dinner </td>
    <td class='diary' width='25%' ><?php include($_SERVER['DOCUMENT_ROOT'] . '/includes/marsh.inc.php'); ?></td>
    <td class='diary' width='24%'><a class='diary' href='mailto:judyzz@geraldc.co.uk?subject=Annual_Dinner_2007'>Judith Little</a> on 01234 567890 </td>
    </tr>
    <?php } ?>

    That's what I'd probably do anyways. There is probably no need to echo all the static HTML out, and might make it easier for bugs to enter in.


Bookmarks

Posting Permissions

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