jej1216 Posted February 27, 2009 Share Posted February 27, 2009 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 Share on other sites More sharing options...
samshel Posted February 27, 2009 Share Posted February 27, 2009 include("../includes/db.php");//relative path OR include("/var/www/html/www.sitename.com/includes/db.php");//relative path OR Quote Link to comment Share on other sites More sharing options...
jej1216 Posted February 27, 2009 Author Share Posted February 27, 2009 Thanks, Samshel Exactly what I needed. jej1216 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.