Hey everyone,
What I'm trying to do is create a link on a page that retrieves and display content from a database.
The link goes to a page...
localhost/resolve/viewprojectsarticle.php?title=title
With "title"being the name of the article it is going to display.
The "viewprojectsarticle" page comes up except I get this error...
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /Applications/xampp/xamppfiles/htdocs/resolve/includes/DbConnector.php on line 50
The code I am using to retrieve the information is as below...
<?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, image, content, related, related2, related3, staff, staff2, staff3 FROM projects WHERE title = '.$HTTP_GET_VARS['title']);
// Get an array containing the resulting record
$row = $connector->fetchArray($result);
?>
<br><b><?php echo $row['title'];?></b><p>
<img src="images/<?php echo $row['image'];?>">
<p>
<?php echo $row['content'];?>
<p><b>Related Services</b><p>
<?php echo $row['related'];?>
<br>
<?php echo $row['related2'];?>
<br>
<?php echo $row['related3'];?>
<p><b>Staff Involvement</b><p>
<?php echo $row['staff'];?>
<br>
<?php echo $row['staff2'];?>
<br>
<?php echo $row['staff3'];?>
The DBconnector.php file is as below...
<?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);
}
}
?>
Please help I am stuck on what to do!