Jump to content

path to include folder


gwh

Recommended Posts

Hi everyone,

 

When I'm testing locally, I have to add the name of the site folder as part of the path name when I'm including files, eg.

 

include $_SERVER['DOCUMENT_ROOT'] . '/site_name/includes/dbAdmin.inc.php';

 

Eventually when I upload the site to the hosting provider I'll need to remove the site name, ie.

 

include $_SERVER['DOCUMENT_ROOT'] . '/includes/dbAdmin.inc.php';

 

This is because the includes folder will be in the root directory.

 

This is going to be a real pain as I'd have to remove quite a lot of them, so I wondered if there was a way to avoid having to include the site name when testing or a workaround?

 

Appreciate any tips.

 

Link to comment
Share on other sites

What does $_SERVER['DOCUMENT_ROOT'] actually return on local server? It should default to htdocs or public_html, meaning you have no need to enter 'sitename'.

 

Are you having it in a different folder you mean? htdocs\site_name\includes\? Then predefine a variable..

if ($_SERVER['HTTP_HOST'] == "127.0.0.1") { 
   define ('__ROOT__', $_SERVER['DOCUMENT_ROOT'] . '/site_name/');
} else {
   define ('__ROOT__', $_SERVER['DOCUMENT_ROOT']);
}

 

You can include  it, or add that to the top. So..

 

include("__ROOT__/includes/foo.php");

will work either way.

Link to comment
Share on other sites

Thanks for the reply,

 

Yeah I've got it in a different folder.

 

So say I add your code to the top of the file:

 

if ($_SERVER['HTTP_HOST'] == "127.0.0.1") {

  define ('__ROOT__', $_SERVER['DOCUMENT_ROOT'] . '/site_name/');

} else {

  define ('__ROOT__', $_SERVER['DOCUMENT_ROOT']);

}

 

...will "127.0.0.1" be the same on my computer or something different? If different, how do I find out what it is?

 

 

Link to comment
Share on other sites

Thanks for the reply,

 

Yeah I've got it in a different folder.

 

So say I add your code to the top of the file:

 

if ($_SERVER['HTTP_HOST'] == "127.0.0.1") {

  define ('__ROOT__', $_SERVER['DOCUMENT_ROOT'] . '/site_name/');

} else {

  define ('__ROOT__', $_SERVER['DOCUMENT_ROOT']);

}

 

...will "127.0.0.1" be the same on my computer or something different? If different, how do I find out what it is?

 

If you're on your local server, your host will always be (127.0.0.1/site_name/includes/). The code basically says. "If it is local, add /site_name" .. "If it is not local, do not add sitename" (/htdocs/includes/) so when you upload it, your code will set the proper directory exclusively.

 

Link to comment
Share on other sites

So after adding the code to the top, will all my includes start with __ROOT__/includes/ as you have it:

 

include("__ROOT__/includes/foo.php");

 

Yes. The __ROOT__ will change based on if it is localhost or on your site server.

Link to comment
Share on other sites

I get the following errors when I try it:

 

Warning: include_once(/Applications/MAMP/htdocs__ROOT__/includes/magicquotes.inc.php) [function.include-once]: failed to open stream: No such file or directory in /Applications/MAMP/htdocs/new_site/admin/catalogue/categories/index.php on line 10

Warning: include_once() [function.include]: Failed opening '/Applications/MAMP/htdocs__ROOT__/includes/magicquotes.inc.php' for inclusion (include_path='.:/Applications/MAMP/bin/php5/lib/php') in /Applications/MAMP/htdocs/new_site/admin/catalogue/categories/index.php on line 10

Warning: include(/Applications/MAMP/htdocs__ROOT__/includes/dbAdmin.inc.php) [function.include]: failed to open stream: No such file or directory in /Applications/MAMP/htdocs/new_site/admin/catalogue/categories/index.php on line 164

Warning: include() [function.include]: Failed opening '/Applications/MAMP/htdocs__ROOT__/includes/dbAdmin.inc.php' for inclusion (include_path='.:/Applications/MAMP/bin/php5/lib/php') in /Applications/MAMP/htdocs/new_site/admin/catalogue/categories/index.php on line 164

Notice: Undefined variable: link in /Applications/MAMP/htdocs/new_site/admin/catalogue/categories/index.php on line 165

Warning: mysqli_query() expects parameter 1 to be mysqli, null given in /Applications/MAMP/htdocs/new_site/admin/catalogue/categories/index.php on line 165

Notice: Undefined variable: link in /Applications/MAMP/htdocs/new_site/admin/catalogue/categories/index.php on line 168

Warning: mysqli_error() expects parameter 1 to be mysqli, null given in /Applications/MAMP/htdocs/new_site/admin/catalogue/categories/index.php on line 168

Warning: include(/Applications/MAMP/htdocs__ROOT__/includes/error.inc.html.php) [function.include]: failed to open stream: No such file or directory in /Applications/MAMP/htdocs/new_site/admin/catalogue/categories/index.php on line 169

Warning: include() [function.include]: Failed opening '/Applications/MAMP/htdocs__ROOT__/includes/error.inc.html.php' for inclusion (include_path='.:/Applications/MAMP/bin/php5/lib/php') in /Applications/MAMP/htdocs/new_site/admin/catalogue/categories/index.php on line 169

 

Any ideas why?

Link to comment
Share on other sites

This is the code on the page:

<?php
if ($_SERVER['HTTP_HOST'] == "127.0.0.1") { 
   define ('__ROOT__', $_SERVER['DOCUMENT_ROOT'] . '/new_site/');
} else {
   define ('__ROOT__', $_SERVER['DOCUMENT_ROOT']);
}


include_once $_SERVER['DOCUMENT_ROOT'] .
	'__ROOT__/includes/magicquotes.inc.php';


if (isset($_GET['add']))
{
$pagetitle = 'New category';
$action = 'addform';
$name = '';
$email = '';
$catID = '';
$button = 'Add author';

include 'form.html.php';
exit();
}

if (isset($_GET['addform']))
{
include $_SERVER['DOCUMENT_ROOT'] . '__ROOT__/includes/dbAdmin.inc.php';

$category = mysqli_real_escape_string($link, $_POST['category']);
$sql = "INSERT INTO categories SET
		category='$category'";
if (!mysqli_query($link, $sql))
{
	$error = 'Error adding submitted category.';
	include 'error.html.php';
	exit();
}

header('Location: .');
exit();
}

if (isset($_POST['action']) and $_POST['action'] == 'Edit')
{
include $_SERVER['DOCUMENT_ROOT'] . '__ROOT__/includes/dbAdmin.inc.php';

$id = mysqli_real_escape_string($link, $_POST['catID']);
$sql = "SELECT catID, category FROM categories WHERE catID='$id'";
$result = mysqli_query($link, $sql);
if (!$result)
{
	$error = 'Error fetching category details.';
	include 'error.html.php';
	exit();
}
$row = mysqli_fetch_array($result);

$pagetitle = 'Edit category';
$action = 'editform';
$category = $row['category'];
$catID = $row['catID'];
$button = 'Update category';

include 'form.html.php';
exit();
}

if (isset($_GET['editform']))
{
include $_SERVER['DOCUMENT_ROOT'] . '__ROOT__/includes/dbAdmin.inc.php';

$catID = mysqli_real_escape_string($link, $_POST['catID']);
$category = mysqli_real_escape_string($link, $_POST['category']);
$sql = "UPDATE categories SET
		category='$category'
		WHERE catID='$catID'";
if (!mysqli_query($link, $sql))
{
	$error = 'Error updating submitted category.';
	include 'error.html.php';
	exit();
}

header('Location: .');
exit();
}


if (isset($_POST['action']) and $_POST['action'] == 'Delete')
{
include $_SERVER['DOCUMENT_ROOT'] . '__ROOT__/includes/dbAdmin.inc.php';
$id = mysqli_real_escape_string($link, $_POST['catID']);

// Get items with certain category
$sql = "SELECT itemID FROM items WHERE catID='$id'";
$item_result = mysqli_query($link, $sql);

if (!$item_result)
{
	$error = 'Error getting list of items to delete: ' . mysqli_error($link);
	include $_SERVER['DOCUMENT_ROOT'] . '__ROOT__/includes/error.inc.html.php';
	exit();
}


$sql = "SELECT catID, category FROM categories WHERE catID='$id'";
$category_result = mysqli_query($link, $sql);

if (!$category_result)
{
	$error = 'Error getting category to display: ' . mysqli_error($link);
	include $_SERVER['DOCUMENT_ROOT'] . '__ROOT__/includes/error.inc.html.php';
	exit();
}


// assume that no match has been found
	$recordsExist = false;


// check whether recordset found any matches
if (mysqli_num_rows($item_result) > 0) {

	$recordsExist = true;

	list($catID, $category) = mysqli_fetch_row($category_result);

 	include 'category_delete.html.php';
	exit();

	 	}
		elseif (mysqli_num_rows($item_result) == 0) {

		list($catID, $category) = mysqli_fetch_row($category_result);

		include 'category_delete.html.php';
		exit();
		}	
}


 // Delete the category

if (isset($_POST['action']) and $_POST['action'] == 'Confirm deletion')
{
	include $_SERVER['DOCUMENT_ROOT'] . '__ROOT__/includes/dbAdmin.inc.php';
	$id = mysqli_real_escape_string($link, $_POST['catID']);

	$sql = "DELETE FROM categories WHERE catID='$id'";
	if (!mysqli_query($link, $sql))
		{
			$error = 'Error deleting category: ' . mysqli_error($link);
			include $_SERVER['DOCUMENT_ROOT'] . '__ROOT__/includes/error.inc.html.php';
			exit();
		}

		header('Location: .');
		exit();
}


// Display category list
include $_SERVER['DOCUMENT_ROOT'] . '__ROOT__/includes/dbAdmin.inc.php';
$result = mysqli_query($link, 'SELECT catID, category FROM categories');
if (!$result)
{
$error = 'Error fetching categories from database! – ' . mysqli_error($link);
include $_SERVER['DOCUMENT_ROOT'] . '__ROOT__/includes/error.inc.html.php';
exit();
}

while ($row = mysqli_fetch_array($result))
{
$categories[] = array('catID' => $row['catID'], 'category' => $row['category']);
}

include 'categories.html.php';
?>

 

Link to comment
Share on other sites

I changed the quotes with the following code updated:

<?php
if ($_SERVER['HTTP_HOST'] == "127.0.0.1") { 
   define ('__ROOT__', $_SERVER['DOCUMENT_ROOT'] . '/new_site/');
} else {
   define ('__ROOT__', $_SERVER['DOCUMENT_ROOT']);
}


include_once $_SERVER['DOCUMENT_ROOT'] .
	"__ROOT__/includes/magicquotes.inc.php";


if (isset($_GET['add']))
{
$pagetitle = 'New category';
$action = 'addform';
$name = '';
$email = '';
$catID = '';
$button = 'Add author';

include 'form.html.php';
exit();
}

if (isset($_GET['addform']))
{
include $_SERVER['DOCUMENT_ROOT'] . "__ROOT__/includes/dbAdmin.inc.php";

$category = mysqli_real_escape_string($link, $_POST['category']);
$sql = "INSERT INTO categories SET
		category='$category'";
if (!mysqli_query($link, $sql))
{
	$error = 'Error adding submitted category.';
	include 'error.html.php';
	exit();
}

header('Location: .');
exit();
}

if (isset($_POST['action']) and $_POST['action'] == 'Edit')
{
include $_SERVER['DOCUMENT_ROOT'] . "__ROOT__/includes/dbAdmin.inc.php";

$id = mysqli_real_escape_string($link, $_POST['catID']);
$sql = "SELECT catID, category FROM categories WHERE catID='$id'";
$result = mysqli_query($link, $sql);
if (!$result)
{
	$error = 'Error fetching category details.';
	include 'error.html.php';
	exit();
}
$row = mysqli_fetch_array($result);

$pagetitle = 'Edit category';
$action = 'editform';
$category = $row['category'];
$catID = $row['catID'];
$button = 'Update category';

include 'form.html.php';
exit();
}

if (isset($_GET['editform']))
{
include $_SERVER['DOCUMENT_ROOT'] . "__ROOT__/includes/dbAdmin.inc.php";

$catID = mysqli_real_escape_string($link, $_POST['catID']);
$category = mysqli_real_escape_string($link, $_POST['category']);
$sql = "UPDATE categories SET
		category='$category'
		WHERE catID='$catID'";
if (!mysqli_query($link, $sql))
{
	$error = 'Error updating submitted category.';
	include 'error.html.php';
	exit();
}

header('Location: .');
exit();
}


if (isset($_POST['action']) and $_POST['action'] == 'Delete')
{
include $_SERVER['DOCUMENT_ROOT'] . "__ROOT__/includes/dbAdmin.inc.php";
$id = mysqli_real_escape_string($link, $_POST['catID']);

// Get items with certain category
$sql = "SELECT itemID FROM items WHERE catID='$id'";
$item_result = mysqli_query($link, $sql);

if (!$item_result)
{
	$error = 'Error getting list of items to delete: ' . mysqli_error($link);
	include $_SERVER['DOCUMENT_ROOT'] . "__ROOT__/includes/error.inc.html.php";
	exit();
}


$sql = "SELECT catID, category FROM categories WHERE catID='$id'";
$category_result = mysqli_query($link, $sql);

if (!$category_result)
{
	$error = 'Error getting category to display: ' . mysqli_error($link);
	include $_SERVER['DOCUMENT_ROOT'] . "__ROOT__/includes/error.inc.html.php";
	exit();
}


// assume that no match has been found
	$recordsExist = false;


// check whether recordset found any matches
if (mysqli_num_rows($item_result) > 0) {

	$recordsExist = true;

	list($catID, $category) = mysqli_fetch_row($category_result);

 	include 'category_delete.html.php';
	exit();

	 	}
		elseif (mysqli_num_rows($item_result) == 0) {

		list($catID, $category) = mysqli_fetch_row($category_result);

		include 'category_delete.html.php';
		exit();
		}	
}


 // Delete the category

if (isset($_POST['action']) and $_POST['action'] == 'Confirm deletion')
{
	include $_SERVER['DOCUMENT_ROOT'] . "__ROOT__/includes/dbAdmin.inc.php";
	$id = mysqli_real_escape_string($link, $_POST['catID']);

	$sql = "DELETE FROM categories WHERE catID='$id'";
	if (!mysqli_query($link, $sql))
		{
			$error = 'Error deleting category: ' . mysqli_error($link);
			include $_SERVER['DOCUMENT_ROOT'] . "__ROOT__/includes/error.inc.html.php";
			exit();
		}

		header('Location: .');
		exit();
}


// Display category list
include $_SERVER['DOCUMENT_ROOT'] . "__ROOT__/includes/dbAdmin.inc.php";
$result = mysqli_query($link, 'SELECT catID, category FROM categories');
if (!$result)
{
$error = 'Error fetching categories from database! – ' . mysqli_error($link);
include $_SERVER['DOCUMENT_ROOT'] . "__ROOT__/includes/error.inc.html.php";
exit();
}

while ($row = mysqli_fetch_array($result))
{
$categories[] = array('catID' => $row['catID'], 'category' => $row['category']);
}

include 'categories.html.php';
?>

 

I'm still getting the errors?

 

Link to comment
Share on other sites

I tried this:

<?php
if ($_SERVER['HTTP_HOST'] == "127.0.0.1") { 
   define ('__ROOT__', $_SERVER['DOCUMENT_ROOT'] . '/new_site/');
} else {
   define ('__ROOT__', $_SERVER['DOCUMENT_ROOT']);
}


include_once $_SERVER['DOCUMENT_ROOT'] .
	"/includes/magicquotes.inc.php";


if (isset($_GET['add']))
{
$pagetitle = 'New category';
$action = 'addform';
$name = '';
$email = '';
$catID = '';
$button = 'Add author';

include 'form.html.php';
exit();
}

if (isset($_GET['addform']))
{
include $_SERVER['DOCUMENT_ROOT'] . "/includes/dbAdmin.inc.php";

$category = mysqli_real_escape_string($link, $_POST['category']);
$sql = "INSERT INTO categories SET
		category='$category'";
if (!mysqli_query($link, $sql))
{
	$error = 'Error adding submitted category.';
	include 'error.html.php';
	exit();
}

header('Location: .');
exit();
}

if (isset($_POST['action']) and $_POST['action'] == 'Edit')
{
include $_SERVER['DOCUMENT_ROOT'] . "/includes/dbAdmin.inc.php";

$id = mysqli_real_escape_string($link, $_POST['catID']);
$sql = "SELECT catID, category FROM categories WHERE catID='$id'";
$result = mysqli_query($link, $sql);
if (!$result)
{
	$error = 'Error fetching category details.';
	include 'error.html.php';
	exit();
}
$row = mysqli_fetch_array($result);

$pagetitle = 'Edit category';
$action = 'editform';
$category = $row['category'];
$catID = $row['catID'];
$button = 'Update category';

include 'form.html.php';
exit();
}

if (isset($_GET['editform']))
{
include $_SERVER['DOCUMENT_ROOT'] . "/includes/dbAdmin.inc.php";

$catID = mysqli_real_escape_string($link, $_POST['catID']);
$category = mysqli_real_escape_string($link, $_POST['category']);
$sql = "UPDATE categories SET
		category='$category'
		WHERE catID='$catID'";
if (!mysqli_query($link, $sql))
{
	$error = 'Error updating submitted category.';
	include 'error.html.php';
	exit();
}

header('Location: .');
exit();
}


if (isset($_POST['action']) and $_POST['action'] == 'Delete')
{
include $_SERVER['DOCUMENT_ROOT'] . "/includes/dbAdmin.inc.php";
$id = mysqli_real_escape_string($link, $_POST['catID']);

// Get items with certain category
$sql = "SELECT itemID FROM items WHERE catID='$id'";
$item_result = mysqli_query($link, $sql);

if (!$item_result)
{
	$error = 'Error getting list of items to delete: ' . mysqli_error($link);
	include $_SERVER['DOCUMENT_ROOT'] . "/includes/error.inc.html.php";
	exit();
}


$sql = "SELECT catID, category FROM categories WHERE catID='$id'";
$category_result = mysqli_query($link, $sql);

if (!$category_result)
{
	$error = 'Error getting category to display: ' . mysqli_error($link);
	include $_SERVER['DOCUMENT_ROOT'] . "/includes/error.inc.html.php";
	exit();
}


// assume that no match has been found
	$recordsExist = false;


// check whether recordset found any matches
if (mysqli_num_rows($item_result) > 0) {

	$recordsExist = true;

	list($catID, $category) = mysqli_fetch_row($category_result);

 	include 'category_delete.html.php';
	exit();

	 	}
		elseif (mysqli_num_rows($item_result) == 0) {

		list($catID, $category) = mysqli_fetch_row($category_result);

		include 'category_delete.html.php';
		exit();
		}	
}


 // Delete the category

if (isset($_POST['action']) and $_POST['action'] == 'Confirm deletion')
{
	include $_SERVER['DOCUMENT_ROOT'] . "/includes/dbAdmin.inc.php";
	$id = mysqli_real_escape_string($link, $_POST['catID']);

	$sql = "DELETE FROM categories WHERE catID='$id'";
	if (!mysqli_query($link, $sql))
		{
			$error = 'Error deleting category: ' . mysqli_error($link);
			include $_SERVER['DOCUMENT_ROOT'] . "__ROOT__/includes/error.inc.html.php";
			exit();
		}

		header('Location: .');
		exit();
}


// Display category list
include $_SERVER['DOCUMENT_ROOT'] . "/includes/dbAdmin.inc.php";
$result = mysqli_query($link, 'SELECT catID, category FROM categories');
if (!$result)
{
$error = 'Error fetching categories from database! – ' . mysqli_error($link);
include $_SERVER['DOCUMENT_ROOT'] . "/includes/error.inc.html.php";
exit();
}

while ($row = mysqli_fetch_array($result))
{
$categories[] = array('catID' => $row['catID'], 'category' => $row['category']);
}

include 'categories.html.php';
?>

 

I'm still getting errors. I don't know what the problem is?

Link to comment
Share on other sites

I tried the following:

<?php
if ($_SERVER['HTTP_HOST'] == "127.0.0.1") { 
   define ('__ROOT__', $_SERVER['DOCUMENT_ROOT'] . '/new_site/');
} else {
   define ('__ROOT__', $_SERVER['DOCUMENT_ROOT']);
}

include_once("__ROOT__/includes/magicquotes.inc.php");


if (isset($_GET['add']))
{
$pagetitle = 'New category';
$action = 'addform';
$name = '';
$email = '';
$catID = '';
$button = 'Add author';

include 'form.html.php';
exit();
}

if (isset($_GET['addform']))
{
include("__ROOT__/includes/dbAdmin.inc.php");

$category = mysqli_real_escape_string($link, $_POST['category']);
$sql = "INSERT INTO categories SET
		category='$category'";
if (!mysqli_query($link, $sql))
{
	$error = 'Error adding submitted category.';
	include 'error.html.php';
	exit();
}

header('Location: .');
exit();
}

if (isset($_POST['action']) and $_POST['action'] == 'Edit')
{
include("__ROOT__/includes/dbAdmin.inc.php");

$id = mysqli_real_escape_string($link, $_POST['catID']);
$sql = "SELECT catID, category FROM categories WHERE catID='$id'";
$result = mysqli_query($link, $sql);
if (!$result)
{
	$error = 'Error fetching category details.';
	include 'error.html.php';
	exit();
}
$row = mysqli_fetch_array($result);

$pagetitle = 'Edit category';
$action = 'editform';
$category = $row['category'];
$catID = $row['catID'];
$button = 'Update category';

include 'form.html.php';
exit();
}

if (isset($_GET['editform']))
{
include("__ROOT__/includes/dbAdmin.inc.php");

$catID = mysqli_real_escape_string($link, $_POST['catID']);
$category = mysqli_real_escape_string($link, $_POST['category']);
$sql = "UPDATE categories SET
		category='$category'
		WHERE catID='$catID'";
if (!mysqli_query($link, $sql))
{
	$error = 'Error updating submitted category.';
	include 'error.html.php';
	exit();
}

header('Location: .');
exit();
}


if (isset($_POST['action']) and $_POST['action'] == 'Delete')
{
include("__ROOT__/includes/dbAdmin.inc.php");
$id = mysqli_real_escape_string($link, $_POST['catID']);

// Get items with certain category
$sql = "SELECT itemID FROM items WHERE catID='$id'";
$item_result = mysqli_query($link, $sql);

if (!$item_result)
{
	$error = 'Error getting list of items to delete: ' . mysqli_error($link);
	include 'error.html.php';
	exit();
}


$sql = "SELECT catID, category FROM categories WHERE catID='$id'";
$category_result = mysqli_query($link, $sql);

if (!$category_result)
{
	$error = 'Error getting category to display: ' . mysqli_error($link);
	include 'error.html.php';
	exit();
}


// assume that no match has been found
	$recordsExist = false;


// check whether recordset found any matches
if (mysqli_num_rows($item_result) > 0) {

	$recordsExist = true;

	list($catID, $category) = mysqli_fetch_row($category_result);

 	include 'category_delete.html.php';
	exit();

	 	}
		elseif (mysqli_num_rows($item_result) == 0) {

		list($catID, $category) = mysqli_fetch_row($category_result);

		include 'category_delete.html.php';
		exit();
		}	
}


 // Delete the category

if (isset($_POST['action']) and $_POST['action'] == 'Confirm deletion')
{
	include("__ROOT__/includes/dbAdmin.inc.php");
	$id = mysqli_real_escape_string($link, $_POST['catID']);

	$sql = "DELETE FROM categories WHERE catID='$id'";
	if (!mysqli_query($link, $sql))
		{
			$error = 'Error deleting category: ' . mysqli_error($link);
			include 'error.html.php';
			exit();
		}

		header('Location: .');
		exit();
}


// Display category list
include("__ROOT__/includes/dbAdmin.inc.php");
$result = mysqli_query($link, 'SELECT catID, category FROM categories');
if (!$result)
{
$error = 'Error fetching categories from database! – ' . mysqli_error($link);
include 'error.html.php';
exit();
}

while ($row = mysqli_fetch_array($result))
{
$categories[] = array('catID' => $row['catID'], 'category' => $row['category']);
}

include 'categories.html.php';
?>

 

But I'm still getting these errors:

 

Warning: include_once(__ROOT__/includes/magicquotes.inc.php) [function.include-once]: failed to open stream: No such file or directory in /Applications/MAMP/htdocs/new_site/admin/catalogue/categories/index.php on line 8

Warning: include_once() [function.include]: Failed opening '__ROOT__/includes/magicquotes.inc.php' for inclusion (include_path='.:/Applications/MAMP/bin/php5/lib/php') in /Applications/MAMP/htdocs/new_site/admin/catalogue/categories/index.php on line 8

Warning: include(__ROOT__/includes/dbAdmin.inc.php) [function.include]: failed to open stream: No such file or directory in /Applications/MAMP/htdocs/new_site/admin/catalogue/categories/index.php on line 162

Warning: include() [function.include]: Failed opening '__ROOT__/includes/dbAdmin.inc.php' for inclusion (include_path='.:/Applications/MAMP/bin/php5/lib/php') in /Applications/MAMP/htdocs/new_site/admin/catalogue/categories/index.php on line 162

Notice: Undefined variable: link in /Applications/MAMP/htdocs/new_site/admin/catalogue/categories/index.php on line 163

Warning: mysqli_query() expects parameter 1 to be mysqli, null given in /Applications/MAMP/htdocs/new_site/admin/catalogue/categories/index.php on line 163

Notice: Undefined variable: link in /Applications/MAMP/htdocs/new_site/admin/catalogue/categories/index.php on line 166

Warning: mysqli_error() expects parameter 1 to be mysqli, null given in /Applications/MAMP/htdocs/new_site/admin/catalogue/categories/index.php on line 166
Error fetching categories from database! –

 

Any further help from anyone would be really appreciated.

Link to comment
Share on other sites

Sorry. Change the beginning to this:

if ($_SERVER['HTTP_HOST'] == "127.0.0.1") { 
   define ('__ROOT__', $_SERVER['DOCUMENT_ROOT'] . '/new_site');
} else {
   define ('__ROOT__', $_SERVER['DOCUMENT_ROOT']);
}

 

I forgot, definitions cannot appear inside quotes, Try this:

include_once(__ROOT__ . "/includes/magicquotes.inc.php");

 

Sorry again, I'm tired. This should work, I tested an example on my machine.

Link to comment
Share on other sites

I'm still getting the errors:

 

Warning: include_once(/Applications/MAMP/htdocs/includes/magicquotes.inc.php) [function.include-once]: failed to open stream: No such file or directory in /Applications/MAMP/htdocs/new_site/admin/catalogue/categories/index.php on line 8

Warning: include_once() [function.include]: Failed opening '/Applications/MAMP/htdocs/includes/magicquotes.inc.php' for inclusion (include_path='.:/Applications/MAMP/bin/php5/lib/php') in /Applications/MAMP/htdocs/new_site/admin/catalogue/categories/index.php on line 8

Warning: include(/Applications/MAMP/htdocs/includes/dbAdmin.inc.php) [function.include]: failed to open stream: No such file or directory in /Applications/MAMP/htdocs/new_site/admin/catalogue/categories/index.php on line 162

Warning: include() [function.include]: Failed opening '/Applications/MAMP/htdocs/includes/dbAdmin.inc.php' for inclusion (include_path='.:/Applications/MAMP/bin/php5/lib/php') in /Applications/MAMP/htdocs/new_site/admin/catalogue/categories/index.php on line 162

Notice: Undefined variable: link in /Applications/MAMP/htdocs/new_site/admin/catalogue/categories/index.php on line 163

Warning: mysqli_query() expects parameter 1 to be mysqli, null given in /Applications/MAMP/htdocs/new_site/admin/catalogue/categories/index.php on line 163

Notice: Undefined variable: link in /Applications/MAMP/htdocs/new_site/admin/catalogue/categories/index.php on line 166

Warning: mysqli_error() expects parameter 1 to be mysqli, null given in /Applications/MAMP/htdocs/new_site/admin/catalogue/categories/index.php on line 166
Error fetching categories from database! –

 

Current code is:

<?php
if ($_SERVER['HTTP_HOST'] == "127.0.0.1") { 
   define ('__ROOT__', $_SERVER['DOCUMENT_ROOT'] . '/new_site');
} else {
   define ('__ROOT__', $_SERVER['DOCUMENT_ROOT']);
}

include_once(__ROOT__ . "/includes/magicquotes.inc.php");


if (isset($_GET['add']))
{
$pagetitle = 'New category';
$action = 'addform';
$name = '';
$email = '';
$catID = '';
$button = 'Add author';

include 'form.html.php';
exit();
}

if (isset($_GET['addform']))
{
include(__ROOT__ . "/includes/dbAdmin.inc.php");

$category = mysqli_real_escape_string($link, $_POST['category']);
$sql = "INSERT INTO categories SET
		category='$category'";
if (!mysqli_query($link, $sql))
{
	$error = 'Error adding submitted category.';
	include 'error.html.php';
	exit();
}

header('Location: .');
exit();
}

if (isset($_POST['action']) and $_POST['action'] == 'Edit')
{
include(__ROOT__ . "/includes/dbAdmin.inc.php");

$id = mysqli_real_escape_string($link, $_POST['catID']);
$sql = "SELECT catID, category FROM categories WHERE catID='$id'";
$result = mysqli_query($link, $sql);
if (!$result)
{
	$error = 'Error fetching category details.';
	include 'error.html.php';
	exit();
}
$row = mysqli_fetch_array($result);

$pagetitle = 'Edit category';
$action = 'editform';
$category = $row['category'];
$catID = $row['catID'];
$button = 'Update category';

include 'form.html.php';
exit();
}

if (isset($_GET['editform']))
{
include(__ROOT__ . "/includes/dbAdmin.inc.php");

$catID = mysqli_real_escape_string($link, $_POST['catID']);
$category = mysqli_real_escape_string($link, $_POST['category']);
$sql = "UPDATE categories SET
		category='$category'
		WHERE catID='$catID'";
if (!mysqli_query($link, $sql))
{
	$error = 'Error updating submitted category.';
	include 'error.html.php';
	exit();
}

header('Location: .');
exit();
}


if (isset($_POST['action']) and $_POST['action'] == 'Delete')
{
include(__ROOT__ . "/includes/dbAdmin.inc.php");
$id = mysqli_real_escape_string($link, $_POST['catID']);

// Get items with certain category
$sql = "SELECT itemID FROM items WHERE catID='$id'";
$item_result = mysqli_query($link, $sql);

if (!$item_result)
{
	$error = 'Error getting list of items to delete: ' . mysqli_error($link);
	include 'error.html.php';
	exit();
}


$sql = "SELECT catID, category FROM categories WHERE catID='$id'";
$category_result = mysqli_query($link, $sql);

if (!$category_result)
{
	$error = 'Error getting category to display: ' . mysqli_error($link);
	include 'error.html.php';
	exit();
}


// assume that no match has been found
	$recordsExist = false;


// check whether recordset found any matches
if (mysqli_num_rows($item_result) > 0) {

	$recordsExist = true;

	list($catID, $category) = mysqli_fetch_row($category_result);

 	include 'category_delete.html.php';
	exit();

	 	}
		elseif (mysqli_num_rows($item_result) == 0) {

		list($catID, $category) = mysqli_fetch_row($category_result);

		include 'category_delete.html.php';
		exit();
		}	
}


 // Delete the category

if (isset($_POST['action']) and $_POST['action'] == 'Confirm deletion')
{
	include(__ROOT__ . "/includes/dbAdmin.inc.php");
	$id = mysqli_real_escape_string($link, $_POST['catID']);

	$sql = "DELETE FROM categories WHERE catID='$id'";
	if (!mysqli_query($link, $sql))
		{
			$error = 'Error deleting category: ' . mysqli_error($link);
			include 'error.html.php';
			exit();
		}

		header('Location: .');
		exit();
}


// Display category list
include(__ROOT__ . "/includes/dbAdmin.inc.php");
$result = mysqli_query($link, 'SELECT catID, category FROM categories');
if (!$result)
{
$error = 'Error fetching categories from database! – ' . mysqli_error($link);
include 'error.html.php';
exit();
}

while ($row = mysqli_fetch_array($result))
{
$categories[] = array('catID' => $row['catID'], 'category' => $row['category']);
}

include 'categories.html.php';
?>

 

Any further suggestions?

 

Link to comment
Share on other sites

"/Applications/MAMP/htdocs/includes/magicquotes.inc.php"

 

Then that doesn't exist. What are you running that on? Does your MAMP server have it running on localhost (127.0.0.1)?

 

If it isn't, then it won't work. Change 127.0.0.1 to whatever your MAMP server is set up to run on.

Link to comment
Share on other sites

It's running on localhost 8889 so I tried:

 

if ($_SERVER['HTTP_HOST'] == "8889")

 

It didn't work.

 

echo $_SERVER['HTTP_HOST']; <-- Run that.

It should say "localhost" so you can put that in place of 127.0.0.1. I've never worked with a mac network before..

Link to comment
Share on other sites

The following didn't work either:

 

<?php
if ($_SERVER['HTTP_HOST'] != "new_site.net.au") { 
   define ('__ROOT__', $_SERVER['DOCUMENT_ROOT'] . '/new_site');
} else {
   define ('__ROOT__', $_SERVER['DOCUMENT_ROOT']);
}

 

Still getting the same errors

Link to comment
Share on other sites

So say I add your code to the top of the file:

 

The code being discussed should be located in a configuration file (config.php) that you then include/require into each page that needs it.

 

You are stating that the errors are the same. How about posting the error messages as the problem may in fact be something else than the original problem (such as a missing /).

Link to comment
Share on other sites

Are you sure HTTP_HOST is new_site.net.au on your web host?

 

So new_site.net.au should be the domain name? Is that what you're saying? If yes, then I've changed it to the domain name and it still doesn't work.

 

The code being discussed should be located in a configuration file (config.php) that you then include/require into each page that needs it.

 

I have a lot of config.php files on my computer so I wouldn't know where to begin to look and I don't know which piece of code I'm looking for.

 

You are stating that the errors are the same. How about posting the error messages as the problem may in fact be something else than the original problem (such as a missing /).

 

The following are the errors again:

Warning: include_once(/Applications/MAMP/htdocs/new_site/includes/magicquotes.inc.php) [function.include-once]: failed to open stream: No such file or directory in /Applications/MAMP/htdocs/new_site/admin/catalogue/categories/index.php on line 7

Warning: include_once() [function.include]: Failed opening '/Applications/MAMP/htdocs/new_site/includes/magicquotes.inc.php' for inclusion (include_path='.:/Applications/MAMP/bin/php5/lib/php') in /Applications/MAMP/htdocs/new_site/admin/catalogue/categories/index.php on line 7

Warning: include(/Applications/MAMP/htdocs/new_site/includes/dbAdmin.inc.php) [function.include]: failed to open stream: No such file or directory in /Applications/MAMP/htdocs/new_site/admin/catalogue/categories/index.php on line 161

Warning: include() [function.include]: Failed opening '/Applications/MAMP/htdocs/new_site/includes/dbAdmin.inc.php' for inclusion (include_path='.:/Applications/MAMP/bin/php5/lib/php') in /Applications/MAMP/htdocs/new_site/admin/catalogue/categories/index.php on line 161

Notice: Undefined variable: link in /Applications/MAMP/htdocs/new_site/admin/catalogue/categories/index.php on line 162

Warning: mysqli_query() expects parameter 1 to be mysqli, null given in /Applications/MAMP/htdocs/new_site/admin/catalogue/categories/index.php on line 162

Notice: Undefined variable: link in /Applications/MAMP/htdocs/new_site/admin/catalogue/categories/index.php on line 165

Warning: mysqli_error() expects parameter 1 to be mysqli, null given in /Applications/MAMP/htdocs/new_site/admin/catalogue/categories/index.php on line 165
Error fetching categories from database! –

 

These errors only appeared after inserting the code block offered in this post.

 

 

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.