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 8 of 8
  1. #1
    Regular Coder
    Join Date
    Dec 2006
    Posts
    166
    Thanks
    9
    Thanked 4 Times in 4 Posts

    Can't call a function from an included file

    Hmmm. I can't figure out why, but I get this error:
    Fatal error: Call to undefined function: generate_header() in /*directory*/index2.php on line 10

    When I run this script (index2.php):
    Code:
    <?php
    include (head.php);
    generate_header();
    ?>
    head.php
    Code:
    <?php
    function generate_header() {
    	echo ('<center>
    	<table style="border:none; width:768" border="0">
    		<tr>
    			<td colspan="3"><a href="index.php"><img src="images/banner.jpg" alt="Home" border="0" /></a></td>
    		</tr>
    		<tr style="height:50;">
    			<!--<td height="50"><a href="index.php"><img src="images/nav_icon.jpg" alt="Home" border="0" align="top" /></a></td>
    			<td style="width:709; background-image:url(images/nav_bg.JPG); height:50;"></td>
    			<td><img src="images/nav_right.jpg" border="0" align="top" />	</tr> -->
    			<td style="height:50; width:768;"><img src="images/nav_whole.jpg" border="0" usemap="#Nav" /></td>
    		<map name="Nav" id="Nav"><area shape="rect" coords="150,3,206,24" href="index.php" target="" />
    			<area shape="rect" coords="220,3,385,24" href="#" />
    			<area shape="rect" coords="399,3,484,24" href="#" />
    			<area shape="rect" coords="498,3,571,24" href="#" />
    			<area shape="rect" coords="588,3,666,24" href="#" />
    			<area shape="rect" coords="72,26,322,46" href="#" /><area shape="rect" coords="342,26,399,46" href="#" />
    			<area shape="rect" coords="419,26,494,46" href="#" /><area shape="rect" coords="513,26,594,46" href="#" /><area shape="rect" 				coords="613,26,751,46" href="#" />
    			<area shape="rect" coords="1,0,50,50" href="index.php" />
    		</map>
    </table>
    </center>');
    }
    ?>
    Last edited by 194673; 12-29-2006 at 07:29 AM. Reason: edited to most recent. Thanks for pointing that out whizard

  • #2
    Senior Coder whizard's Avatar
    Join Date
    Jan 2005
    Location
    Philadelphia, PA, USA
    Posts
    1,662
    Thanks
    14
    Thanked 76 Times in 76 Posts
    You call a function named generate_header(), but your included file creates a function named generate_head()...

    Dan
    PHP Tip: If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.

    Don't forget to save everyone time and mark your thread as Resolved :)

    "Also note that it is your responsibility to die() if necessary."

    DON'T USE THE MYSQL_ EXTENSION

  • #3
    Regular Coder
    Join Date
    Dec 2006
    Posts
    166
    Thanks
    9
    Thanked 4 Times in 4 Posts
    Whoops, forgot to mention I already changed them so they match. Thanks for the suggestion though, but the problem still persists

  • #4
    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
    Try
    PHP Code:
    <?php
    include 'head.php';
    generate_header();
    ?>
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #5
    Senior Coder whizard's Avatar
    Join Date
    Jan 2005
    Location
    Philadelphia, PA, USA
    Posts
    1,662
    Thanks
    14
    Thanked 76 Times in 76 Posts
    It needs to be

    PHP Code:
    include('head.php');
    generate_header(); 
    (no space between the include statement and the parentheses <edit>and/or single quotes as Aero mentioned</edit>)

    Dan
    Last edited by whizard; 12-29-2006 at 07:34 AM.
    PHP Tip: If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.

    Don't forget to save everyone time and mark your thread as Resolved :)

    "Also note that it is your responsibility to die() if necessary."

    DON'T USE THE MYSQL_ EXTENSION

  • #6
    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
    If you had used an editor with syntax highlighting you would notice that the include statement is incorrect. The include state requires a string meaning it needs to be in quotes
    PHP Code:
    <?php
    include (head.php);
    generate_header();
    ?>
    PHP Code:
    <?php
    include ('head.php');
    generate_header();
    ?>
    Parentheses are optional.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #7
    Senior Coder whizard's Avatar
    Join Date
    Jan 2005
    Location
    Philadelphia, PA, USA
    Posts
    1,662
    Thanks
    14
    Thanked 76 Times in 76 Posts
    Also, from my own experience, I find it helpful to have a print statement at the beginning of each file I include that simply prints the filename to the browser, so I can tell whether or not my file has successfully been included

    (I comment it out once I am done troubleshooting it)

    PS- Can you tell I'm bored?



    Dan
    PHP Tip: If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.

    Don't forget to save everyone time and mark your thread as Resolved :)

    "Also note that it is your responsibility to die() if necessary."

    DON'T USE THE MYSQL_ EXTENSION

  • #8
    Regular Coder
    Join Date
    Dec 2006
    Posts
    166
    Thanks
    9
    Thanked 4 Times in 4 Posts
    Wow I must be blind. Can't believe I overlooked that. Thanks for the help guys!


  •  

    Posting Permissions

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