Jump to content

[SOLVED] Fatal error: Call to undefined function...


Errant_Shadow

Recommended Posts

I can find a lot of resources online to solve unidentified function errors for -specific- things. Mostly built-in functions like mysql_connect. The problem is that it can't find a function that -I- wrote, that it sitting RIGHT THERE in the damn script. I thought maybe it was some stupidness happening with my include_once line, but then I just took that out and put the function itself in there and it -STILL- can't find it...

 

// include_once "http://".$_SERVER['SERVER_NAME']."/scripts/functions/checkInput(input).php";
// used to strip slashes or escape data
function checkInput ($input) {
// connect to mySQL
$dbc = @mysql_connect("localhost", "NAME", "PASS") or die("&err_msg=MYSQL Error (Could not connect to database).");
// select database ($databaseName)
@mysql_select_db("rey619_bigtop") or die("&err_msg=MYSQL Error! " . mysql_error($dbc));
// if the input uses magic quotes... strip the slashes
if (get_magic_quotes_gpc()) { $input = stripslashes($input); }
// if the input is NOT numeric... escape the data
if (!is_numeric($input)) { $input = mysql_real_escape_string($input); }
// close mySQL connection
mysql_close($dbc);
// finally, return the input
return $input;
} // end function check_input ($input)

// 339 lines later, inside some nested IF,THEN,ELSE statements...

$test = "What's my line?";
$test = checkInput($test);
echo "<p>" . $test . "</p>";

 

echoes:

Fatal error: Call to undefined function checkinput() in /home/rey619/public_html/register/index.php on line 108

 

So my question is, as always, wtf?

Link to comment
Share on other sites

Your function definition is probably inside of some conditional logic or inside of a comment or inside of an other function definition.

 

Post more of the code around the function definition.

 

And DON'T open a database connection, then close it just to run a single mysql_real_escape_string() function on a piece of data. That will make your code run about 50 times slower than necessary.

Link to comment
Share on other sites

Alright, I'll modify the sql connection; thank you.

 

The function definition exists in header.php, which is included into every page and the include lines exist at the top of the scripts to be free of all functions and conditionals, and before any html is sent to the page.

 

After trying a few other things I got it to work when I paste the script directly into the page itself, rather than the header, which is included in the page. I know the header is being included because it formats the page correctly. Additionally, I can access a -different- function that I included in the same way, just not this one for some reason.

Link to comment
Share on other sites

Using a URL in an include statement only causes the HTML output from the code in the included file to be included. It does not cause the php code in the included file to be included. You must include files using a local file path if you want php code, such as function definitions to exist in the file they are included into.

Link to comment
Share on other sites

ah... well that's a lot easier than what I was about to do >>

 

$includePrefix = "";

if ($_SERVER['REQUEST_URI'] != "/") { $includePrefix = "../"; }

include_once $includePrefix . "scripts/functions/scaleImage(imgLink,maxWidth,maxHeight).php";
include_once $includePrefix . "scripts/functions/checkInput(input).php";

 

Thank you, I really appreciate your help; I wasn't aware that PHP treated full HTML URL's that way.

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.