Hi there, I've used the tutorial to create the basic for an intranet, but I keep getting an error. I know others had that problem aswell, I've looked through the forum for a solution but nothing works. All the solutions are solved (I checked the code and nothing seems wrong).
The error I get is this:
Code:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\intranet test\includes\DbConnector.php on line 50
So here I post the code I have:
DbConnector.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['dbhost'];
$db = $settings['dbname'];
$user = $settings['dbusername'];
$pass = $settings['dbpassword'];
// 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: getQuery, Purpose: Returns the last database query, for debugging ***
function getQuery() {
return $this->theQuery;
}
//*** Function: getNumRows, Purpose: Return row count, MySQL version ***
function getNumRows($result){
return mysql_num_rows($result);
}
//*** 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);
}
}
?>
Here the viewarticles.php:
Code:
<?php
// Require the database class
require_once('includes/DbConnector.php');
// Create a new DbConnector object
$connector = new DbConnector();
// IMPORTANT!!! Validate the ID number. See next article
// Execute the query to retrieve the selected article
$result = $connector->query('SELECT title,thearticle FROM cmsarticles WHERE ID = '.$_GET['id']);
// Get an array containing the resulting record
$row = $connector->fetchArray($result);
?>
Your selected article: <?php echo $row['title,tagline'];?>
<br><br>
<?php echo $row['thearticle'];?>
Here is the SystemComponent.php:
Code:
<?php
class SystemComponent {
var $settings;
function getSettings() {
// System variables
$settings['siteDir'] = '../intranet%20test/';
// Database variables
$settings['dbhost'] = 'localhost';
$settings['dbusername'] = 'root';
$settings['dbpassword'] = '';
$settings['dbname'] = 'intratest';
return $settings;
}
}
?>
Hope someone can help me with this problem.