jej1216 Posted February 27, 2009 Share Posted February 27, 2009 Sorry - I double-posted this. I'm redoing some PHP code to put things like the Database info into an include file instead of putting the connect info in the main PHP page. I have it working, but only if I put the php file I want to include in a folder below where my main php resides. Here is my code that works: <?php include("includes/db.php"); ?> <?php $sql = "INSERT INTO my_table (field1, field2) VALUES ('$_REQUEST[field1]', '$_REQUEST[field2]')"; if (!mysql_query($sql,$db)) { die('Error: '.mysql_error()); } mysql_close($db); ?> I would prefer to put the 'includes' folder in a location that is 'beside' the folder that holds the main php file I am working on, not 'below' it. In other words, right now I have this folder structure: 1) htdocs b)-> main i.-> includes I want the structure to be 1) htdocs a)-> main b)-> includes when I move folder to where it is 'beside' the main folder I get this error: "Warning: include(includes/db.php) [function.include]: failed to open stream: No such file or directory in C:\xampp\htdocs\main\main.php " I can't figure out how to identify this folder location in my include line of code. I also tried <?php include("http://localhost/includes/db.php"); ?> and got this error: "Warning: include() [function.include]: URL file-access is disabled in the server configuration in C:\xampp\htdocs\main\main.php.... Warning: include(http://localhost/includes/db.php) [function.include]: failed to open stream: no suitable wrapper could be found in C:\xampp\htdocs\main\main.php.... Warning: include() [function.include]: Failed opening 'http://localhost/includes/db.php' for inclusion (include_path='.;C:\xampp\php\pear\') in C:\xampp\htdocs\main\main.php " I appreciate the help. jej1216 Quote Link to comment https://forums.phpfreaks.com/topic/147199-solved-include-issue-with-folder-location-of-include-file-sorry-double-post/ Share on other sites More sharing options...
premiso Posted February 27, 2009 Share Posted February 27, 2009 <?php include($_SERVER['DOCUMENT_ROOT'] . "/includes/db.php"); ?> I tend to use the php variable document_root when including files so it includes it via the absolute path, not relative. Quote Link to comment https://forums.phpfreaks.com/topic/147199-solved-include-issue-with-folder-location-of-include-file-sorry-double-post/#findComment-772745 Share on other sites More sharing options...
jej1216 Posted February 27, 2009 Author Share Posted February 27, 2009 premiso, Thanks - works like a charm. And "Read the Forum Rules, who knows you may learn how to post properly on PHP Freaks!" would not have helped. I had the browser opened and was called away for an extended time, came back and posted it, did not see it in the list afterwards. I thought I must have lost the connection, so I posted it again and later saw it in the list twice. What can I say, it's Friday! Thanks again. jej1216 Quote Link to comment https://forums.phpfreaks.com/topic/147199-solved-include-issue-with-folder-location-of-include-file-sorry-double-post/#findComment-772770 Share on other sites More sharing options...
premiso Posted February 27, 2009 Share Posted February 27, 2009 That is part of my signature, it is attached to all my posts. Quote Link to comment https://forums.phpfreaks.com/topic/147199-solved-include-issue-with-folder-location-of-include-file-sorry-double-post/#findComment-772776 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.