Jump to content
Larry Ullman's Book Forums

Base_Uri And Url


Recommended Posts

Hi Forum Members,

 

I've been struggling for some time on the above topic. I've tried everything I've read but

still can't get it to work in xampp. Can someone help me please.

 

Directories structure

C:xampp\htdocs\

 

 

 

The error I'm getting is as follows:

 

Fatal error: require(): Failed opening required 'C:\xampp\htdocs\mysql_inc.php' (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\index.php on line

 

 

And my code is as follows:

 

config.inc.php

 

//Base url constants declaration

define ('BASE_URI', 'C:\\xampp\htdocs\\');

define ('BASE_URL', 'localhost/');

define ('MYSQL', BASE_URI . 'mysql_inc.php');

 

//starting a session for the logins

session_start();

 

mysql.inc.php

 

<?php

//define constants for the db connection

DEFINE ('DB_HOST', 'localhost');

DEFINE ('DB_USER', 'AMPONSAH');

DEFINE ('DB_PASSORD', 'password');

DEFINE ('DB_NAME', 'ecommerce1');

 

//connect to mysql

$dbc = mysqli_connect (DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);

//----------------------------- MYSQL CONNECTION ------------------------------------------------------

//establish character set

mysqli_set_charset($dbc, 'utf8');

Link to comment
Share on other sites

Hi Rob,

 

Please find the code below.

 

index.php

 

 

<?php

require ('includes/config.inc.php');

include ('includes/header.html');

require (MYSQL);

?>

<h3>Welcome</h3>

<p>Welcome to Knowledge is Power, a site dedicated to keeping you up to date on the web security and programming information you need to know. Blah, blah, blah.</p>

 

<?php

include ('includes/footer.html');

?>

Link to comment
Share on other sites

Right, you're not done yet; all you've done is establish there's an issue with the value you're setting for BASE_URI.

 

Echo the value of $_SERVER['DOCUMENT_ROOT'], insert this value into BASE_URI and change your script back to require(MYSQL).

 

Does the script now work? If not, post the line of the BASE_URI with it's value from the config file.

Link to comment
Share on other sites

Put the following code in any file that's in htdocs that you can run via the browser, copy the value you see on the page and paste it into the config file as your value for BASE_URI.

 

echo 'Document root: ' . $_SERVER['DOCUMENT_ROOT'];

 

If you're new to PHP this book could be difficult for you as it assumes PHP knowledge, you'd probably be better getting larry's latest edition of PHP and MySQL http://www.larryullm...de-4th-edition/ and work through that book first.

Link to comment
Share on other sites

This is what I got "Document root: C:/xampp/htdocs" and have inserted it.

 

define ('BASE_URL', 'Document root: C:/xampp/htdocs');

define ('BASE_URL', 'localhost/');

define ('MYSQL', BASE_URI . 'mysql_inc.php');

 

and on index.php, I change this "require($_SERVER['DOCUMENT_ROOT'] . '\mysql.inc.php');"

back to "require (MYSQL);" but this is what I got:

 

 

Fatal error: require(): Failed opening required 'BASE_URImysql_inc.php' (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\index.php on line 4

 

This is my second book after the recommended php for the web book but I don't remember seeing

anything like this.

Link to comment
Share on other sites

 Share

×
×
  • Create New...