Errant_Shadow Posted July 22, 2009 Share Posted July 22, 2009 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? Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted July 22, 2009 Share Posted July 22, 2009 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. Quote Link to comment Share on other sites More sharing options...
Errant_Shadow Posted July 22, 2009 Author Share Posted July 22, 2009 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. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted July 22, 2009 Share Posted July 22, 2009 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. Quote Link to comment Share on other sites More sharing options...
Errant_Shadow Posted July 22, 2009 Author Share Posted July 22, 2009 So a partial URL, like just "scripts/functions/..." ? Since header.php is being called from different places, the local path will change. For some pages it will be "scripts/functions/..." but others will have to be "../scripts/function/..." Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted July 22, 2009 Share Posted July 22, 2009 In php that's not a URL (partial, relative, or otherwise.) In php that is a file path. To form an absolute file path, relative to the document root folder, use include $_SERVER['DOCUMENT_ROOT'] . '\the_path\the_file.php'; Quote Link to comment Share on other sites More sharing options...
Errant_Shadow Posted July 22, 2009 Author Share Posted July 22, 2009 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.