0

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.

9
  • I'm sure you know this, but just in case, you know that you are passing, literally, the string "$userid" and NOT what that represents, right? (for your script, that should actually be empty). Commented May 14, 2012 at 13:32
  • $userid is declared in my script. Commented May 14, 2012 at 13:33
  • if it's declared in that same function or declared as a global (as it should be to have some value inside the function), you should write this: addNoti("You just joined us!",$userid); Commented May 14, 2012 at 13:34
  • Search all your sources for "addNoti"... Commented May 14, 2012 at 13:37
  • After reading all the answers I am very much curious to know where exactly the problem is :-) Commented May 14, 2012 at 13:38

4 Answers 4

2

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)

Sign up to request clarification or add additional context in comments.

Comments

1

Is it a typo? In your question you name the function addNotification and addNoti()...

Comments

0

Do you call doRegister() before addNoti() occurred in your script?! That is the question!

2 Comments

As said in my question: "A couple of hundreds line BELOW that^ (same page), I have my registration function "register":" - therefore, I first declare the addNoti function, and THEN call the doRegister()
Also, if he calls the function doRegister(), before ocurring both, it should give the error for this function, and not for the addNoti..
0

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)?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.