Reputation: 4302
I want to require_once()
dbconnect.php
in register.php
. How do I do that? I tried require_once('../dbconnect.php')
but that does not work (though it does work at the register
level.
Upvotes: 1
Views: 591
Reputation: 617
When u do
require_once('../dbconnect.php')
.. means the parent directory, so it goes one level up there. Still its there in the register folder. So, to go to its parent directory, you will have to specify one more .. where the file dbconnect.php exists. So you can also use it as
require_once __DIR__. '/../dbconnect.php';
Upvotes: 0
Reputation: 527
your code is true, from register folder, you will need to use require_once(../dbconnect.php)
. well, now we see require_once()
, "once" is mean it have to included only one time, maybe just check your code. is require_once(../dbconnect.php)
has been located at this script or other script that included? if you type require_once(../dbconnect.php)
more than one, this will error.
Upvotes: 0
Reputation: 711
Is dbconnect.php inside public_html? if so you will need require_once('../../dbconnect.php')
Each ../ represents one directory up. At the moment it's looking in register for dbconnect.php
Upvotes: 1
Reputation: 490323
require_once dirname(__FILE__) . '/../../dbconnect.php';
Or if you are using PHP 5.3, replace dirname(__FILE__)
with __DIR__
.
If you wanted to be real anal, you could replace /
with the constant DIRECTORY_SEPARATOR
. :P
Upvotes: 2