Hello all,
I want to create my own (still simple) content management system. To do this, I used the IntranetJournal.com tutorial. However, I get an error message at step 3 (
http://www.intranetjournal.com/artic...09_07_04a.html). On my localhost (created with WampServer, PHP and MySQL were automatically installed using that program), I've created the neccesary files and I've completely done what the tutorial tells me to do. This is my file tree:
c:/wamp/www (localhost root) contains:
- cmsadmin (empty folder)
- images (empty folder)
- includes (folder, contains following files):
- DbConnector.php
- SystemComponent.php
- templates (empty folder)
- newArticle.php
- nieuwartikel.htm (this is the article submission form as discribed in step 3 of the tutorial)
When I tried to test creating an article via nieuwartikel.htm, I got the following errors when I click the Submit button:
HTML Code:
Warning: require_once(../includes/DbConnector.php) [function.require-once]: failed to open stream: No such file or directory in C:\wamp\www\newArticle.php on line 3
Fatal error: require_once() [function.require]: Failed opening required '../includes/DbConnector.php' (include_path='.;C:\php5\pear') in C:\wamp\www\newArticle.php on line 3
I've already Googled it, but I haven't found an answer. To help you with diagnosing the problem, I'll provide the code of the different files.
My DbConnector.php file contains the following code:
PHP Code:
<?php
////////////////////////////////////////////////////////////////////////////////////////
// Class: DbConnector
// Purpose: Connect to a database, MySQL version
///////////////////////////////////////////////////////////////////////////////////////
require_once 'SystemComponent.php';
class DbConnector extends SystemComponent {
var $theQuery;
var $link;
//*** Function: DbConnector, Purpose: Connect to the database ***
function DbConnector(){
// Load settings from parent class
$settings = SystemComponent::getSettings();
// Get the main settings from the array we just loaded
$host = $settings['localhost'];
$db = $settings['interlycealedb'];
$user = $settings['root'];
$pass = $settings[''];
// Connect to the database
$this->link = mysql_connect($host, $user, $pass);
mysql_select_db($db);
register_shutdown_function(array(&$this, 'close'));
}
//*** Function: query, Purpose: Execute a database query ***
function query($query) {
$this->theQuery = $query;
return mysql_query($query, $this->link);
}
//*** Function: fetchArray, Purpose: Get array of query results ***
function fetchArray($result) {
return mysql_fetch_array($result);
}
//*** Function: close, Purpose: Close the connection ***
function close() {
mysql_close($this->link);
}
}
?>
My SystemComponent.php file contains the follwing code:
PHP Code:
<?php
class SystemComponent {
var $settings;
function getSettings() {
// System variables
$settings['siteDir'] = 'localhost/';
// Database variables
$settings['dbhost'] = 'localhost';
$settings['dbusername'] = 'root';
$settings['dbpassword'] = '';
$settings['dbname'] = 'mytestdb';
return $settings;
}
}
?>
My newArticle.php file contains the following code:
PHP Code:
<?php
// Get the PHP file containing the DbConnector class
require_once('../includes/DbConnector.php');
// Check whether a form has been submitted. If so, carry on
if ($HTTP_POST_VARS){
// Create an instance of DbConnector
$connector = new DbConnector();
// IMPORTANT!! ADD FORM VALIDATION CODE HERE - SEE THE NEXT ARTICLE
// Create an SQL query (MySQL version)
$query = "INSERT INTO cmsarticles (title, tagline, section, thearticle) VALUES
('".$title."', '".$tagline."', '".$section."', '".$thearticle."')";
// Save the form data into the database
if ($result = $connector->query($insertQuery)){
// It worked, give confirmation
echo '<center><b>Article added to the database</b></center><br>';
}else{
// It hasn't worked so stop. Better error handling code would be good here!
exit('<center>Sorry, there was an error saving to the database</center>');
}
}
?>
The nieuwartikel.htm file functions correctly. I really hope someone can help me!
Kind regards,
Tvdm