Page 1 of 1
calling a function from a different php page
Posted: Sat Sep 19, 2009 1:46 pm
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.
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.
Re: calling a function from a different php page
Posted: Sat Sep 19, 2009 1:53 pm
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?
Re: calling a function from a different php page
Posted: Sat Sep 19, 2009 2:04 pm
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
Re: calling a function from a different php page
Posted: Sat Sep 19, 2009 2:08 pm
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.

Re: calling a function from a different php page
Posted: Sat Sep 19, 2009 2:33 pm
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.