Jump to content

function defined, but isnt detected? (inbedded in a require?)


leeming

Recommended Posts

basicly i have my index page..

[code]
//call const
require_once("wwc_const.php");

//call functions
require_once("wwc_functions.php");[/code]

which the const page, calls a function, which gets the id of the user from their login name...

not sure if this is due to if the functions file is set as require_once (but i tried them both as include and same problem)...

[quote]
Fatal error: Call to undefined function: getidfromuser() in /home2/admin/public_html/wwc_const.php on line 8[/quote]

wwc_const.php  line #8
[code]  DEFINE("USERID", getIDFromUser($_SESSION[wwc_user]));[/code]

wwc_functions.php function
[code]function getIDFromUser($user)
{
  $sql = "select Account_ID from Accounts WHERE Account_UName = '$user'";
  $query = mysql_query($sql, cdb(0))or bavaderror($sql);
  $result = mysql_fetch_array($query);
 
  return $result[Account_ID];
}[/code]
Link to comment
Share on other sites

[quote author=businessman332211 link=topic=105663.msg422171#msg422171 date=1156556560]
Try just an include, see if that works.
[/quote]
i did say i had tried that :S
[quote author=leeming link=topic=105663.msg422166#msg422166 date=1156555783]

not sure if this is due to if the functions file is set as require_once (but i tried them both as include and same problem)...
[/quote]


i am calling the function (in line order) before its defined, but functions can be declared at the bottom of the page arnt they... :S
Link to comment
Share on other sites

[quote] but functions can be declared at the bottom of the page arnt they... :S[/quote]
functions HAVE to be declared before the function is called.
As for your problem, just as a test try declaring the function on the same page, then see if it works, just try declaring it at the top of the page.  See if you get the same error.  If not then try
the function_exists() function, see if it returns true.
That will let you know if the function even exists, if it returns false when it's on the same page then something is wrong with your function itself.
Link to comment
Share on other sites

[quote]
functions HAVE to be declared before the function is called.
[/quote]

really? i was under the understanding that aslong as they are declared on the code, they can be called... (same understanding for other programming languages)

i can put the functions on my main index page.. instead of in a functions page.. but i have never had this problem before.. (it also makes my index.php page more scruffy looking)

if i declare the function above or below on the same page it still works.. (just since i have 3 custom functions called in the 'const' page.. which 2 of them (bavaderror() and cdb() are lengthy declarations), so if i put these on the main index page.. it defeats the purpose of having a functions.php page (???)...

like i said.. i have never had this problem before.. if i cant fix it (without resorting to making my code look scruffy and disordered) i will have to be forced to rearange my code
Link to comment
Share on other sites

You can keep all your functions in a seperate file as is what I do.. Just put your require statement before you are going to call the function..  Thats all that needs to happen..  If its going to break your code -- you might re-think your coding style.
Link to comment
Share on other sites

[quote]functions HAVE to be declared before the function is called.[/quote]

That is INCORRECT. You can use a function before it is declared in php. However... what you are trying to do is use a function before the file it is within is included. This will not work.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.