Jump to content


Photo

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


  • Please log in to reply
8 replies to this topic

#1 leeming

leeming
  • Members
  • PipPipPip
  • Advanced Member
  • 93 posts

Posted 26 August 2006 - 01:29 AM

basicly i have my index page..

//call const
require_once("wwc_const.php");

//call functions
require_once("wwc_functions.php");

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

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


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

wwc_functions.php function
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];
}

Im not perfect ;) lol

#2 corbin

corbin
  • Staff Alumni
  • Advanced Member
  • 8,129 posts

Posted 26 August 2006 - 01:41 AM

Are you calling the function previous to the require_once statement?
Why doesn't anyone ever say hi, hey, or whad up world?

#3 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 26 August 2006 - 01:42 AM

Try just an include, see if that works.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#4 leeming

leeming
  • Members
  • PipPipPip
  • Advanced Member
  • 93 posts

Posted 26 August 2006 - 01:45 AM

Try just an include, see if that works.

i did say i had tried that :S


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



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
Im not perfect ;) lol

#5 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 26 August 2006 - 01:49 AM

but functions can be declared at the bottom of the page arnt they... :S

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.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#6 leeming

leeming
  • Members
  • PipPipPip
  • Advanced Member
  • 93 posts

Posted 26 August 2006 - 01:59 AM

functions HAVE to be declared before the function is called.


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
Im not perfect ;) lol

#7 radar

radar
  • Members
  • PipPipPip
  • Advanced Member
  • 645 posts
  • LocationSLC

Posted 26 August 2006 - 06:28 AM

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.

#8 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 26 August 2006 - 08:15 AM

functions HAVE to be declared before the function is called.


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.

#9 Zane

Zane
  • Administrators
  • Advanced Member
  • 4,134 posts

Posted 26 August 2006 - 08:20 AM

just switch the order of these two and it should work

require_once("wwc_const.php");
require_once("wwc_functions.php");

just require the funcitons.php first and then const.php

btn_donate_SM.gif Want to thank me? Contribute to my PayPal piggy-bank
 

172938.png




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users