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
simonmlewis
DevNet Master
Posts: 4435 Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:
Post
by simonmlewis » Mon Apr 08, 2013 3:46 am
Code: Select all
$menu = $_GET['menu'];
if ($menu != "")
{
function getMenu()
{
$thismenu="includes/menu/".$_GET['menu'].".inc";
if (file_exists($thismenu))
{
include $thismenu;
}
else
{
echo "<meta http-equiv='Refresh' content='0 ;URL=/error'>";
}
}}
..............
$menu = $_REQUEST['menu'];
if(isset($_REQUEST['menu']))
{ getMenu();}
I am getting the error in our logs:
[text][08-Apr-2013 05:49:47] PHP Fatal error: Call to undefined function getmenu() in /home/site/public_html/index.php on line 641[/text]
641 is the latter 'getmenu'.
Why am I getting this?
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
requinix
Spammer :|
Posts: 6617 Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA
Post
by requinix » Mon Apr 08, 2013 12:28 pm
Because the function isn't defined.
And before you say "yes it is, it's right there", notice that you define it inside an if block. If that condition isn't true then the function won't be defined.
simonmlewis
DevNet Master
Posts: 4435 Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:
Post
by simonmlewis » Mon Apr 08, 2013 12:33 pm
But it's only calling the function if $menu is requested in the URL. If it is, it's also called in the functions.
Isn't it?
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
requinix
Spammer :|
Posts: 6617 Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA
Post
by requinix » Mon Apr 08, 2013 2:11 pm
Actually one uses the URL and the other uses whatever information is available, including POSTed data.
Is that actually your code? Did you paraphrase or simplify the code for your post?
simonmlewis
DevNet Master
Posts: 4435 Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:
Post
by simonmlewis » Mon Apr 08, 2013 2:14 pm
That is it, apart from code not related to it. One is te bit to draw in the at, one is the function. He should it be then?
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
requinix
Spammer :|
Posts: 6617 Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA
Post
by requinix » Mon Apr 08, 2013 2:42 pm
What is the URL of this page?
simonmlewis
DevNet Master
Posts: 4435 Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:
Post
by simonmlewis » Mon Apr 08, 2013 2:45 pm
I varies, but via the ht access, it would include ...&menu=categ...
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
simonmlewis
DevNet Master
Posts: 4435 Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:
Post
by simonmlewis » Mon Apr 08, 2013 5:05 pm
Is this correct?
Code: Select all
$menu= isset($_GET['menu']) ? $_GET['menu'] : null;
$menu = $_REQUEST['menu'];
if ($menu != "")
{ getMenu();}
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
simonmlewis
DevNet Master
Posts: 4435 Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:
Post
by simonmlewis » Wed Apr 10, 2013 5:26 am
Answer: No. I am still getting the errors.
What should it be??
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
simonmlewis
DevNet Master
Posts: 4435 Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:
Post
by simonmlewis » Wed Apr 10, 2013 5:45 am
Code: Select all
function getMenu()
{
$thismenu="includes/menu/".$_GET['menu'].".inc";
if (file_exists($thismenu))
{
include $thismenu;
}
else
{
echo "<meta http-equiv='Refresh' content='0 ;URL=/error'>";
}
}
Should it be like this then - just a function there NOT inside an if statement??
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
requinix
Spammer :|
Posts: 6617 Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA
Post
by requinix » Wed Apr 10, 2013 1:52 pm
Yes actually, you should define functions and classes and such at the very top level - not inside anything conditional.
I still don't know why it thinks the function is undefined. Moving it to the top should definitely fix it.
simonmlewis
DevNet Master
Posts: 4435 Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:
Post
by simonmlewis » Wed Apr 10, 2013 1:56 pm
It was always at the top. But I have tried it outside the if statement. Is this what it should be, outside the IF?
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
requinix
Spammer :|
Posts: 6617 Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA
Post
by requinix » Wed Apr 10, 2013 3:29 pm
If it's inside something then it's not at the top.
Yes, outside. Outside everything.
simonmlewis
DevNet Master
Posts: 4435 Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:
Post
by simonmlewis » Thu Apr 11, 2013 5:12 am
Thanks. Now trying that. Will see in the morning if all those errors have gone.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
simonmlewis
DevNet Master
Posts: 4435 Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:
Post
by simonmlewis » Mon Apr 15, 2013 8:21 am
Errors gone!
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.