I'm getting this annoying error and haven't been able to fix it yet.
<b>Fatal error: Class 'Console' not found in /home/serellyn/public_html/HEIM/php/nieuwbeheer/console_overview.php on line 45.</b>
Let's first start with the hierarchy which is like this.
index (main page) console_overview (section of page) include/connect (connect to DB) include/console.class (the class)
The index.php requires the connect.php and the console.class.php and loads the console_overview.php. Here's the code:
<?php
require_once('include/connect.php');
require_once('include/console.class.php');
var_dump(file_exists('include/connect.php'));
var_dump(file_exists('include/console.class.php'));
?>
<div id="mainpage" class="main-container inner">
<?php
if (isset($_GET['page'])) {
$page = $_GET['page'];
} else {
$page = "console_overview";
}
?>
</div>
<!-- end: MAIN CONTAINER -->
<script>
var page = "<?php echo $page;?>";
$( "#mainpage" ).load( page + ".php" );
</script>
I've used var_dumps to check if both file exists (and they do). The console_overview.php loads correctly. Now in the console_overview.php I'm trying to get data from the Console class, as following:
<?php
foreach(Console::getAllConsoles() as $aConsole) {
$consoleID= $aConsole->getID();
$consoleName = $aConsole->getName();
$consoleHostname = $aConsole->getHostname();
$consoleGameID = $aConsole->getGameID();
$consolePowerState = $aConsole->getPowerState();
echo "<tr>";
echo "1";
}
?>
The error I'm getting is caused by the foreach... but I can't find out what's wrong...
The Console class looks like this (I'm pasting the most important parts, otherwise the code would be too long).
<?php
class Console{
private $ID, $hostname, $mac, $ip, $roomID, $gameID, $register, $powerState, $dateUpdated;
public function Console($tID, $tHostname, $tMac, $tIp, $tRoomID, $tGameID, $tRegister, $tPowerState, $tDateUpdated) {
$this->ID = $tID;
$this->hostname = $tHostname;
$this->mac = $tMac;
$this->ip = $tIp;
$this->roomID = $tRoomID;
$this->gameID = $tGameID;
$this->register = $tRegister;
$this->powerState = $tPowerState;
$this->dateUpdated= $tDateUpdated;
}
...
public static function getAllConsoles() {
$sql = "SELECT * FROM `console` ORDER BY `hostname` ASC";
$result = mysql_query($sql);
$theResults = array();
while ($row = mysql_fetch_array($result)) {
$theResults[] = new Console($row[0],$row[1],$row[2],$row[3],$row[4],$row[5],$row[6],$row[7],$row[8],$row[9],$row[10]);
}
return $theResults;
}
}
?>
So can anyone see what the problem is? Thank you for your help.
Edit: O and yes, I know MySQL is deprecated and will change this whenever the issue of not finding the console is fixed =).
requireinside PHP) it creates a new request towards the server. You need to include the PHP files in the javascript loaded PHP files.mysql_*functions you are using are becoming deprecated and will be removed from future versions of PHP. You should not use them to write new code. Usemysqli_*or PDO instead.