joykwame Posted September 12, 2012 Share Posted September 12, 2012 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 More sharing options...
Larry Posted September 13, 2012 Share Posted September 13, 2012 Where did you actually store the mysql.inc.php script? Link to comment Share on other sites More sharing options...
joykwame Posted September 13, 2012 Author Share Posted September 13, 2012 It's been stored in the htdocs folder with the index.php. Link to comment Share on other sites More sharing options...
Edward Posted September 13, 2012 Share Posted September 13, 2012 Change the BASE_URI to this and see if it helps define ('BASE_URI', 'C:\xampp\htdocs\'); Link to comment Share on other sites More sharing options...
joykwame Posted September 13, 2012 Author Share Posted September 13, 2012 No it didn't. Link to comment Share on other sites More sharing options...
rob Posted September 13, 2012 Share Posted September 13, 2012 Post the line of code where you use require( ). Link to comment Share on other sites More sharing options...
joykwame Posted September 13, 2012 Author Share Posted September 13, 2012 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 More sharing options...
rob Posted September 13, 2012 Share Posted September 13, 2012 what happens if you replace the require with the following: require($_SERVER['DOCUMENT_ROOT'] . '\mysql.inc.php'); Link to comment Share on other sites More sharing options...
joykwame Posted September 13, 2012 Author Share Posted September 13, 2012 Wow, that's it. it did the trick. Thanks Rob and everyone. Link to comment Share on other sites More sharing options...
rob Posted September 13, 2012 Share Posted September 13, 2012 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 More sharing options...
joykwame Posted September 13, 2012 Author Share Posted September 13, 2012 hi Rob, do you mean echo "$_SERVER['DOCUMENT_ROOT']"; in config.inf.php file? Sorry, I'm new to this. Link to comment Share on other sites More sharing options...
rob Posted September 13, 2012 Share Posted September 13, 2012 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 More sharing options...
joykwame Posted September 13, 2012 Author Share Posted September 13, 2012 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 More sharing options...
rob Posted September 13, 2012 Share Posted September 13, 2012 Just use the path information for the value: C:/xampp/htdocs Link to comment Share on other sites More sharing options...
joykwame Posted September 13, 2012 Author Share Posted September 13, 2012 thanks a million Link to comment Share on other sites More sharing options...
Recommended Posts