smc Posted January 21, 2007 Share Posted January 21, 2007 Hiya,Alright right now I'm trying to include my configuration file for a file in the admin section. The problem is that for my include file it is in the /www/ directory while the admin file is in /www/admin/. According to php.net the include function works only for the current directory the script is working in. How do I include a file from root in a script that is in /www/admin/?Thanks for any help you can offer!! Link to comment https://forums.phpfreaks.com/topic/35101-paths-for-include/ Share on other sites More sharing options...
Garcia Posted January 21, 2007 Share Posted January 21, 2007 You could just do:[code]include ('admin/admin.php');[/code] Link to comment https://forums.phpfreaks.com/topic/35101-paths-for-include/#findComment-165651 Share on other sites More sharing options...
trq Posted January 21, 2007 Share Posted January 21, 2007 [code=php:0]include '../yourinclude.php';[/code] Link to comment https://forums.phpfreaks.com/topic/35101-paths-for-include/#findComment-165653 Share on other sites More sharing options...
smc Posted January 21, 2007 Author Share Posted January 21, 2007 Garcia I'm trying to get some in root not my current realtive directoryThrope:I tried your example but this is what I got:Warning: dbconnect(./config.php) [function.dbconnect]: failed to open stream: No such file or directory in /home/een/public_html/functions.php on line 23Warning: dbconnect(./config.php) [function.dbconnect]: failed to open stream: No such file or directory in /home/een/public_html/functions.php on line 23Warning: dbconnect(./config.php) [function.dbconnect]: failed to open stream: No such file or directory in /home/een/public_html/functions.php on line 23Warning: dbconnect() [function.include]: Failed opening './config.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/een/public_html/functions.php on line 23Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'een'@'localhost' (using password: NO) in /home/een/public_html/functions.php on line 24Sorry - we could not connect to our database. Please try back later.My guess is that this is because in functions.php I call config.php but since functions is in the same realtive path as config its just ./ as opposed to ../ Is that valid?Thanks,SMC Link to comment https://forums.phpfreaks.com/topic/35101-paths-for-include/#findComment-165663 Share on other sites More sharing options...
inztinkt Posted January 21, 2007 Share Posted January 21, 2007 [quote author=thorpe link=topic=123378.msg509820#msg509820 date=1169394171][code=php:0]include '../yourinclude.php';[/code][/quote]this will work Link to comment https://forums.phpfreaks.com/topic/35101-paths-for-include/#findComment-165671 Share on other sites More sharing options...
smc Posted January 21, 2007 Author Share Posted January 21, 2007 [quote author=inztinkt link=topic=123378.msg509838#msg509838 date=1169397222][quote author=thorpe link=topic=123378.msg509820#msg509820 date=1169394171][code=php:0]include '../yourinclude.php';[/code][/quote]But it didn't :Pthis will work[/quote] Link to comment https://forums.phpfreaks.com/topic/35101-paths-for-include/#findComment-165677 Share on other sites More sharing options...
inztinkt Posted January 21, 2007 Share Posted January 21, 2007 ok wait u have two folders /www/ and /www/admin/WHERE is the file you are working on and WHERE is the file you want included ?:) i iz confuzzled :P Link to comment https://forums.phpfreaks.com/topic/35101-paths-for-include/#findComment-165681 Share on other sites More sharing options...
smc Posted January 21, 2007 Author Share Posted January 21, 2007 Lol sorry okay here is the dealI am working on /www/admin/file.phpfile.php is trying to include /www/functions.phpfunctions.php is trying to include /www/config.phpNow in file.php I have it calling ../functions.phpIn functions.php I have it calling ./config.phpNow I tested it when it was realtive and it worked, but here is the biggest snag:I just tried to by taking what I needed to call from the file and dropping it right in file.php and then commenting out the include line, and it still gave me the same problem saying it couldn't execute the MySQL command.How do I make it say the error in this scenario:$dbh=mysql_connect ($dblocation, $dbusername, $dbpassword)or die ("Sorry - we got lost and couldn't find the database. Please try back later.");$rs=mysql_query($sql,$dbh)or die ("Sorry - for whatever reason we could not execute the SQL command. Please try back later.");Where can I drop mysql_error(); ?Thanks!! Link to comment https://forums.phpfreaks.com/topic/35101-paths-for-include/#findComment-165683 Share on other sites More sharing options...
inztinkt Posted January 21, 2007 Share Posted January 21, 2007 ok lets go back to the original scenario,in [b]functions.php[/b] change the line where it includes config.php to include it remotely like so :[code] include "/config.php"; [/code]and in [b]file.php[/b] change the include to look like this[code] include "/functions.php";[/code]this should work, fingers crossed :P Link to comment https://forums.phpfreaks.com/topic/35101-paths-for-include/#findComment-165685 Share on other sites More sharing options...
smc Posted January 21, 2007 Author Share Posted January 21, 2007 Alright I think I just eliminated the include as the problem, I think I zeroed in on the wrong thing.I just created a file in /www/ called "testroot.php" in that I declared[code=php:0]<?php$apple = "orange";?>[/code]Then I created /www/admin/admin_testroot.php and called[code=php:0]<?php$cms_root_path = '../';include($cms_root_path . 'testroot.php');echo("$apple");?>[/code]And it returned "orange"Now the question is what is wrong with my SQL Link to comment https://forums.phpfreaks.com/topic/35101-paths-for-include/#findComment-165687 Share on other sites More sharing options...
inztinkt Posted January 21, 2007 Share Posted January 21, 2007 simple, [b]comment out[/b] the whole mysql block and add this :[code]$dbh=mysql_connect ($dblocation, $dbusername, $dbpassword)or die(mysql_error());$rs=mysql_query($sql,$dbh)or die (mysql_error());[/code]showing us the errors in mysql, post back with wat it says Link to comment https://forums.phpfreaks.com/topic/35101-paths-for-include/#findComment-165690 Share on other sites More sharing options...
smc Posted January 21, 2007 Author Share Posted January 21, 2007 LOL I forgot to declare which database to connect to.Thanks :P Link to comment https://forums.phpfreaks.com/topic/35101-paths-for-include/#findComment-165703 Share on other sites More sharing options...
inztinkt Posted January 21, 2007 Share Posted January 21, 2007 anytime... glad to have helped you. like many helped me here in the past :) Link to comment https://forums.phpfreaks.com/topic/35101-paths-for-include/#findComment-165710 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.