Jump to content

[SOLVED] Simple question


ninedoors

Recommended Posts

I would like to use one config.php file for all my database connection on my site.  My question is, is there a simple syntax that I can use at the top of the pages I need, instead of including the whole path.

 

Right now I have my config.php file in a config folder so the path is config/config.php.

 

When I try to call it from lets say photos/insert/photos.php php tells me it can't find it.

 

The syntax I use is:

 

include 'config/config.php';

 

I know it's a noobie question but I would like to know because I have been having to put the config file in every folder which kinda negates the point.

Link to comment
Share on other sites

I just tried that and I'm still getting this error:

 

Warning: include(/config/config.php) [function.include]: failed to open stream: No such file or directory in C:\xampp\htdocs\root\photos\insert\album.php on line 5

 

Here's the album.php file

 

<?
// Get values from form 
$nametemp=$_POST['album_name'];

include '/config/config.php';

$name = mysql_real_escape_string($nametemp);

$query = "INSERT INTO gallery_category (category_name) VALUES ('$name')";

mysql_query($query) or die("Query failed due to: ".mysql_error());
mysql_close();

header("Location: ../photos/uploadform.php");

?>

Link to comment
Share on other sites

Nope.  Didin't work either, still got this error:

 

Warning: include(/config/config.php) [function.include]: failed to open stream: No such file or directory in C:\xampp\htdocs\root\photos\insert\album.php on line 5

 

Nick

Link to comment
Share on other sites

No, just put that in there. 

 

I tried putting all folders after the htdocs and failed still.

 

Warning: include(BigC/config/config.php) [function.include]: failed to open stream: No such file or directory in C:\xampp\htdocs\BigC\photos\insert\album.php on line 5

 

Nick

Link to comment
Share on other sites

best idea is to define a constant from the root directory so you don't have to worry about a relative path.  You should do this for all your includes

example

<?php
define("includes_folder", $_SERVER['DOCUMENT_ROOT']."/configs/");
define("DB_CONFIG", includes_folder."db.php");
define("PHP_FUNC", includes_folder."functions.php");

#then to call them its simply
require_once(PHP_FUNC);
require_once(DB_CONFIG);
?>

for files that are configs or "include once" I like to use require_once because the files are both required and only needed once instead of an include function.

Link to comment
Share on other sites

cooldude832

 

where do I put this?

 

<?php
define("includes_folder", $_SERVER['DOCUMENT_ROOT']."/configs/");
define("DB_CONFIG", includes_folder."db.php");
define("PHP_FUNC", includes_folder."functions.php");

?>

 

What file and where?

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.