eternallygeek Posted July 4, 2009 Share Posted July 4, 2009 I am having problems with some PHP code that I am writing. I have a function in a separate php that is included in another php file with html (both shown below). I obviously see the "test() returns...." text but not the return value of 5 from the function. Any thoughts or nudges in the right direction? Here is the html 'calling code'.... (test.php) <html> <?php include '/scripts/testing.php' ?> <head> <title>stuff</title> </head> <body> <p>test() returns....</p> <?php echo test(); ?> </body> </html> Here is the php function library.... (testing.php) <?php function test() { return "5"; } ?> Thanks! Quote Link to comment Share on other sites More sharing options...
Alex Posted July 4, 2009 Share Posted July 4, 2009 Are you sure the file is being included correctly? Make sure the path is right, you're also missing a ; try: include 'scripts/testing.php'; Quote Link to comment Share on other sites More sharing options...
eternallygeek Posted July 5, 2009 Author Share Posted July 5, 2009 Thanks for the reply AlexWD! The semi missing was a typo, I reduced the code down for ease of debugging and placing on the forums here. You were right in pointing me to the included file. I moved the include file into the same directory and included just the filename in quotes. That worked just fine, so there was something wrong with the path. Now I just need to go off and figure out the right path on my webserver so that I can put that file back where I intended it. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted July 5, 2009 Share Posted July 5, 2009 It's usually a good idea to form an absolute file system path starting with the document_root folder - include $_SERVER['DOCUMENT_ROOT'] . '/path_to_file/file.php'; 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.