Jump to content

[SOLVED] Include - issue with folder location of include file - sorry, double post


jej1216

Recommended Posts

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

 

<?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.

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.