...

View Full Version : Can't call a function from an included file



194673
12-29-2006, 07:18 AM
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):

<?php
include (head.php);
generate_header();
?>

head.php

<?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>');
}
?>

whizard
12-29-2006, 07:23 AM
You call a function named generate_header(), but your included file creates a function named generate_head()...

Dan

194673
12-29-2006, 07:28 AM
Whoops, forgot to mention I already changed them so they match. Thanks for the suggestion though, but the problem still persists

_Aerospace_Eng_
12-29-2006, 07:30 AM
Try

<?php
include 'head.php';
generate_header();
?>

whizard
12-29-2006, 07:30 AM
It needs to be



include('head.php');
generate_header();


(no space between the include statement and the parentheses <edit>and/or single quotes as Aero mentioned</edit>)

Dan

_Aerospace_Eng_
12-29-2006, 07:37 AM
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
include (head.php);
generate_header();
?>

<?php
include ('head.php');
generate_header();
?>
Parentheses are optional.

whizard
12-29-2006, 07:40 AM
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?

:D

Dan

194673
12-29-2006, 07:54 AM
Wow I must be blind. Can't believe I overlooked that. Thanks for the help guys!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum