Jump to content

[SOLVED] Include - issue with folder location of include file


jej1216

Recommended Posts

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

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.