calling a function from a different php page

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
eliavozeri
Forum Newbie
Posts: 7
Joined: Sat Sep 19, 2009 1:40 pm

calling a function from a different php page

Post by eliavozeri »

Hi,
i'm kind of new to this php language so here is my question :
i have a function in a file called GeneralFunctions and in that file i have a function called GetWelcomeText
now i'm trying to call that function from my MainPage but for some reason it can't find the function.
i used include("GeneralFunctions.php");
in the beggining of the page and when i use the function file_exists it returns a true value.... so i'm kind of in the woods
about whats wrong. :banghead:
i tried copying the function to the main page and it works there but that is not the solution i'm looking for.
can anyone tell me what is wrong with my code?
thanks for the help.
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Re: calling a function from a different php page

Post by alex.barylski »

What is the error message you receive when you call the function? If you are not receiving any error when calling the funciton, then function is probably being called, but not doing what you need it to.

Inside the function maybe place something like:

Code: Select all

echo 'This function is being called';
exit;
What happens?
eliavozeri
Forum Newbie
Posts: 7
Joined: Sat Sep 19, 2009 1:40 pm

Re: calling a function from a different php page

Post by eliavozeri »

PCSpectra wrote:What is the error message you receive when you call the function? If you are not receiving any error when calling the funciton, then function is probably being called, but not doing what you need it to.

Inside the function maybe place something like:

Code: Select all

echo 'This function is being called';
exit;
What happens?
i get an error message saying :
Fatal error: Call to undefined function GetWelcomeText() in C:\Program Files\wamp\www\fudgemarhomepage.php on line 7
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Re: calling a function from a different php page

Post by alex.barylski »

Are you including the file in which the function GetWelcomeText() resides, before calling it? Perhaps a silly question, just making sure. :)

Second to that, if the code isn't to insane, post it here and we can take a look at it. Otherwise chop out the extraneous stuff and post only the important bits cuz no one will look at more than 20 lines for free. :P
eliavozeri
Forum Newbie
Posts: 7
Joined: Sat Sep 19, 2009 1:40 pm

Re: calling a function from a different php page

Post by eliavozeri »

ok so as i said in the beggining i did include the file in the MainPage so i don't know what the problem is...
so here is what i wrote:

Code: Select all

 
include("GeneralFunctions.php");
if (file_exists("GeneralFunctions.php")) echo "file exists !";
$A=GetWelcomeText();
 
Mind you the file_exists returns a true value and prints "file exists !"
in the GeneralFunctions page i have a function

Code: Select all

 
Function GetWelcomeText()
{
$WelcomeText="Welcome To The Main Page.";
return $WelcomeText;
}
 
i went through the name of the page like 20 times to be sure it is the same name and copied the
name of the function from the page it is in to be sure the name is currect.
still not sure what the problem is.
Post Reply