PHP Include

Discussion in 'PHP' started by Pietercornelis, Dec 8, 2006.

  1. #1
    Hey,

    I'm learning PHP, but I got a problem. When I try to include my menu in all pages in a table cell, through the include command, I do it like this:

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

    Now, I made the menu.php with <html> and <body> tags around it, and also tried it without those tags, but still, the menu.php doesn't show.
    Someone know what I do wrong?

    Thanks!
     
    Pietercornelis, Dec 8, 2006 IP
  2. disgust

    disgust Guest

    Messages:
    2,417
    Likes Received:
    133
    Best Answers:
    0
    Trophy Points:
    0
    #2
    <? include "menu.php"; ?>
    Code (markup):
    should work fine.
     
    disgust, Dec 8, 2006 IP
  3. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #3
    A) Not a good practice to use short tags (<?).
    B) Always use brackets () to make the code readable.

    The above code is perfectly fine and show work, try:

    A) Viewing source
    B) Change include to require, maybe an error might pop up

    Peace,
     
    Barti1987, Dec 8, 2006 IP
  4. disgust

    disgust Guest

    Messages:
    2,417
    Likes Received:
    133
    Best Answers:
    0
    Trophy Points:
    0
    #4
    shrug. I haven't seen a host not support short tags in years.

    the parens in includes just look messy to me. personal preference I guess.

    from what it looks like I'm guessing php isn't even being parsed. if it's not, you should be able to see the actual php code when you view the source. if you can't see it then you probably have error suppression on somewhere.
     
    disgust, Dec 8, 2006 IP
  5. bobby9101

    bobby9101 Peon

    Messages:
    3,292
    Likes Received:
    134
    Best Answers:
    0
    Trophy Points:
    0
    #5
    make sure you backslashed your " in your html... not sure if this even applies to yours, but this is the mistake I always make
     
    bobby9101, Dec 8, 2006 IP
  6. thejared

    thejared Peon

    Messages:
    382
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #6
    You can also make the code like this:
    <?php
    @include("menu.php");
    ?>
    //This is if you don't want errors to show up on the page, if you code doesn't work right.
     
    thejared, Dec 8, 2006 IP
  7. weknowtheworld

    weknowtheworld Guest

    Messages:
    306
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #7
    I think the correct syntax is

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

    Check it that it is in the same folder or elsewhere....

    If it's in abc folder then the syntax will be :

    <?php include("abc/menu.php"); ?>
     
    weknowtheworld, Dec 9, 2006 IP
  8. Pietercornelis

    Pietercornelis Guest

    Messages:
    631
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #8
    The PHP is in the same folder, and the syntax is correct.

    When I open the index page, it still shows nothing, but when I surf to /menu.php with IE, I get to see the menu...
    Any other ideas, anyone?
     
    Pietercornelis, Dec 9, 2006 IP
  9. Nick_Mayhem

    Nick_Mayhem Notable Member

    Messages:
    3,486
    Likes Received:
    338
    Best Answers:
    0
    Trophy Points:
    290
    #9
    <?php
    include("menu.php");
    ?>
    PHP:
    Always works for me.
     
    Nick_Mayhem, Dec 9, 2006 IP
  10. Pietercornelis

    Pietercornelis Guest

    Messages:
    631
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Right. I just can't figure it out. Would someone be willing to review my source code? You'll find it at here. And the menu.php, header.php and right column.

    Thanks in advance.
     
    Pietercornelis, Dec 9, 2006 IP
  11. Pietercornelis

    Pietercornelis Guest

    Messages:
    631
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #11
    Ah! I got it! Apparantly, the index file has to be PHP as well. Sorry, didn't know that! Never mind!
     
    Pietercornelis, Dec 9, 2006 IP