Reputation: 6052
I am trying to add a function named "addNotification" to my page "functions.php"
My function:
function addNoti($text,$userid)
{
mysql_query("INSERT INTO notifications (time,text,userid) VALUES('".time()."','$text','$userid')");
if(mysql_affected_rows() != 1)
return 2;
else
return 100;
}
A couple of hundreds line BELOW that^ (same page), I have my registration function "register":
function doRegister()
{
global $datesetting;
mysql_query("query to register goes here");
addNoti("You just joined us!","$userid");
}
Although, whenever I process my registration form, I get the following error:
Fatal error: Call to undefined function addNoti() in /home/domain/public_html/path/to/functions.php on line 278
(Line 278 is where the addNoti is called)
Whenever I try to move addNoti to another page, and load that page in functions.php I get no error.
Please help.
Thank you in advance.
Upvotes: 0
Views: 136
Reputation: 41050
Is it a typo? In your question you name the function addNotification
and addNoti()
...
Upvotes: 1
Reputation: 5100
From the two functions only it is hard to say what the problem can be. Did you accidently put the function addNoti inside another function (before the closing bracket)?
Upvotes: 0
Reputation: 150
Keep in mind that in PHP you can declare function in conditional block. It could be that in your code execution took the other branch and never got to the function definition. Check the code blocks, check if the code with the function definition gets executed (echo
or var_dump
are your friends)
Upvotes: 2
Reputation: 41050
Do you call doRegister() before addNoti() occurred in your script?! That is the question!
Upvotes: 0