I've searched on the internet for this, and questions here on SO but mostly are using something else than PHP. So i will ask my own question.
What i need to do is make a button that will print out (read literally print, as in downloading a word document with all details on it) every record from the database.
The ID is named 'abstract_id'.
What i'm going to show you next is the print button from all pages, what i mean by this is if you click on said button it will print everything from that specific page:
$abstract_id = addslashes($_POST['abstract_id']);
//Here i connect to the database//
$query = "SELECT * FROM abstracts WHERE abstract_id = '$abstract_id'";
$result = mysql_query($query);
$i = 0;
$title = mysql_result($result,$i,"title");
$author[1] = mysql_result($result,$i,"author1");
$organization[1] = mysql_result($result,$i,"organization1");
$author[2] = mysql_result($result,$i,"author2");
$organization[2] = mysql_result($result,$i,"organization2");
$author[3] = mysql_result($result,$i,"author3");
$organization[3] = mysql_result($result,$i,"organization3");
$author[4] = mysql_result($result,$i,"author4");
$organization[4] = mysql_result($result,$i,"organization4");
$author[5] = mysql_result($result,$i,"author5");
$organization[5] = mysql_result($result,$i,"organization5");
$author[6] = mysql_result($result,$i,"author6");
$organization[6] = mysql_result($result,$i,"organization6");
$format = mysql_result($result,$i,"format");
$language = mysql_result($result,$i,"language");
$presenter = mysql_result($result,$i,"presenter");
$background = mysql_result($result,$i,"background");
$purpose = mysql_result($result,$i,"purpose");
$methods = mysql_result($result,$i,"methods");
$findings = mysql_result($result,$i,"findings");
$conclusion = mysql_result($result,$i,"conclusion");
$word_count = mysql_result($result,$i,"word_count");
$name = mysql_result($result,$i,"name");
$email1 = mysql_result($result,$i,"email1");
$email2 = mysql_result($result,$i,"email2");
$phone1 = mysql_result($result,$i,"phone1");
$phone2 = mysql_result($result,$i,"phone2");
$fax = mysql_result($result,$i,"fax");
$address = mysql_result($result,$i,"address");
$country = mysql_result($result,$i,"country");
$topic = mysql_result($result,$i,"topic");
$master_status = mysql_result($result, $i, "master_status");
$last_edit = mysql_result($result,$i,"last_edit");
header("Content-type: application/vnd.ms-word");
header("Content-Disposition: attachment;Filename=abstract_" . $abstract_id . ".doc");
echo "<html>";
echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=Windows-1252\">";
echo "<body>";
echo "<p><b>PCNE Abstract</b> $abstract_id</p>";
echo "<h1>$title</h1>";
echo "<b>";
for ($i = 1; $i<= 6; $i++) {
echo ((!empty($author[$i-1]) && !empty($author[$i])) ? ", " : "") ;
echo ((!empty($author[$i])) ? $author[$i] . "<sup>" . $i . "</sup>" : "") ;
}
echo ".</b>";
echo "<br>";
for ($i = 1; $i<= 6; $i++) {
if (!empty($author[$i])) {
echo (!empty($organization[$i]) && !empty($organization[$i-1])) ? ". " : "";
echo ((!empty($organization[$i])) ? "<sup>" . $i . "</sup>" . $organization[$i]: "") ;
}
}
echo (!empty($email1)) ? " (" . $email1 . ")" : "";
echo "<br>";
echo "<br>";
echo "<b>Background</b> ";
echo "$background<br>";
echo "<b>Purpose</b> ";
echo "$purpose<br>";
echo "<b>Method</b> ";
echo "$methods<br>";
echo "<b>Findings</b> ";
echo "$findings<br>";
echo "<b>Conclusion</b> ";
echo "$conclusion<br>";
echo "</body>";
echo "</html>";
Now, this works fine, but i need a same working button which does almost the same, but instead of printing out 1 record it should print all. So all i basically need is a foreach or while loop that goes through every abstract_id.
It's been ages since i last programmed php, so i appreciate any help!
If you need any clarification, feel free to ask.
First you don't need your 30 lines of mysql_result, just use mysql_fetch_assoc to get all values in associative array.
Then you just have to do a while ( $line = mysql_fetch_assoc($query) ), see above :
header("Content-type: application/vnd.ms-word");
header("Content-Disposition: attachment;Filename=abstract_all.doc");
echo "<html>";
echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=Windows-1252\">";
echo "<body>";
$query = mysql_query("SELECT * FROM abstracts WHERE 1") or die(mysql_error()) ;
while ( $line = mysql_fetch_assoc($query) )
{
echo "<p><b>PCNE Abstract</b>".$line['abstract_id']."</p>";
echo "<h1>".$line['title']."</h1>";
$authors = Array() ;
for ($i = 1 ; $i <= 6 ; $i++ )
if ( isset($line['author'.$i]) && $line['author'.$i] != '' ) $authors[] = $line['author'.$i].' <sup>'.$i.'</sup>' ;
echo '<b>'.implode(', ',$authors).'</b>' ;
$organizations = Array() ;
for ($i = 1; $i<= 6; $i++)
{
if ( ! isset($line['author'.$i]) || $line['author'.$i] == '' ) continue ; // Check if there is an author, if no go to next loop
if ( isset($line['organization'.$i]) && $line['organization'.$i] != '' ) $organizations[] = ' <sup>'.$i.'</sup> '.$line['organization'.$i] ;
}
echo '<b>'.implode(', ',$organizations).'</b>' ;
echo "<b>Background</b> ";
echo $line['background']."<br>";
echo "<b>Purpose</b> ";
echo $line['purpose']."<br>";
// ...
}
echo "</body>";
echo "</html>";
Related
for ($q = 1 ; $q < 7 ; $q++ )
{
echo $q ; echo $row;
}
now this code works fine but i want to echo 2 rows like in the image below:
I don't want use other for loop,
Can i do it with table html tags ?
You can achieve this using variables that you will echo later just like this:
$tableHeader = "";
$tableRow = "";
for ($q = 1 ; $q < 7 ; $q++ )
{
$tableHeader .= "<th>" . $q . "</th>";
$tableRow .= "<td>". $row ."</td>";
}
echo "<table> <tr>$tableHeader</tr> <tr>$tableRow</tr> </table>";
public function select(){
$rows = [];
$connection = $this->connect();
$result = $connection->query("SELECT username FROM users");
while ($row = $result->fetch_assoc()){
$rows[] = $row;
}
$userlist = 0;
foreach($rows as $username){
$userlist .= $username['username'];
}
$get_rankings = [1,2,3,4];
$get_image_path = "images/";
$total = 0;
for ($x = 0; $x < count($get_rankings); $x++){
$total = $get_rankings[$x];
$path .= "<img src = '" . $get_image_path . $total . ".png'>\n" . $userlist . "<br/>";
// echo "<span class = 'align-down'>{$path}";
// echo "<p class = 'user-name'> {$rows['0']}</p>";
// echo "</span>";
}
echo $path;
}
I'm trying to output a simple ranking but using the number index as images to display them.
In the past i've tried to do something similar but couldn't figure out how to match player it with images on the side.
The output im getting is this:
It's outputting each entry 4 times(I get why, its in a loop) but I can't figure out the correct solution to write it outside of a loop or properly
The desired output is:
My DataBase reads as:
[id][username][password]
If there is an easier solution, i'm all ears. I don't know how to approach this.
There's no need for $userlist. Output the username from $rows[$x].
$path = "";
$max = min(count($rows), count($get_rankings));
for ($x = 0; $x < $max; $x++){
$total = $get_rankings[$x];
$path .= "<img src = '" . $get_image_path . $total . ".png'>\n" . $rows[$x]['username'] . "<br/>";
// echo "<span class = 'align-down'>{$path}";
// echo "<p class = 'user-name'> {$rows['0']}</p>";
// echo "</span>";
}
I am trying to store values from form radio to array. But problem which i am facing is that every time array 1st index is replaced with new value. I believe this is scope problem. I also tried to declare global array but no success.
Here is the code:
<?php
include_once("connection.php");
$c = new DBcon();
$c->startcon();
global $array; // not effecive
// $q = $_POST['t'];
// echo 'fff', $q;
$page = $_GET['page'];
echo 'pagesss', $page, 'ppp';
if ($page == "") {
$page = "1";
} else {
// If page is set, let's get it
$page = $_GET['page'];
}
// Now lets get all messages from your database
$sql = "SELECT * FROM quizes";
$query = mysql_query($sql);
// Lets count all messages
$num = mysql_num_rows($query);
// Lets set how many messages we want to display
$per_page = "2";
// Now we must calculate the last page
$last_page = $num;
echo 's', $num;
// And set the first page
$first_page = "1";
// Here we are making the "First page" link
echo "<a href='?page=" . $first_page . "'>First page</a> ";
// If page is 1 then remove link from "Previous" word
if ($page == $first_page) {
echo "Previous ";
} else {
if (!isset($page)) {
echo "Previous ";
} else {
// But if page is set and it's not 1.. Lets add link to previous word to take us back by one page
$previous = $page - 1;
echo "<a href='?page=" . $previous . "'>Previous</a> ";
}
}
// If the page is last page.. lets remove "Next" link
if ($page == $last_page) {
echo "Next ";
} else {
// If page is not set or it is set and it's not the last page.. lets add link to this word so we can go to the next page
if (!isset($page)) {
$next = $first_page + 1;
echo "<a href='?page=" . $next . "'>Next</a> ";
} else {
$next = $page + 1;
echo "<a href='?page=" . $next . "'>Next</a> ";
}
}
// And now lets add the "Last page" link
echo "<a href='?page=" . $last_page . "'>Last page</a>";
// Math.. It gets us the start number of message that will be displayed
$start = ($page * ($page - 1)) / $page;
echo 'start', $start;
echo 'page', $page;
// Now lets set the limit for our query
$limit = "LIMIT $start, $per_page";
// It's time for getting our messages
$sql = "SELECT * FROM quizes $limit";
$query = mysql_query($sql);
echo "<br /><br />";
// And lets display our messages
$i = 0;
$l = 0;
while ($row = mysql_fetch_array($query) or die(mysql_error())) {
$a = $row['A'];
echo '<form method="get" action="?page=".$next."">';
while ($row = mysql_fetch_array($query)) {
echo '<div class="boxed" >';
echo "\t" . '<tr><th>' .
$row['question'] . "<br>" .
'</th><th>' . "<input type='radio' name= 't[]' value='{$row['A']}'>" . $row['A'] . "<br>" .
'</th><th>' . "<input type='radio' name='t[]' value='{$row['B']}'>" . $row['B'] . "<br>" .
'</th><th>' . "<input type='radio' name='t[]' value='{$row['C']}'>" . $row['C'] . "<br>" .
'</th><th>' . "<input type='radio' name='t[]' value='{$row['D']}'>" . $row['D'] . '</th>
</tr>';
echo '<input type="hidden" name="page" value="' . $next . '">';
echo '<input type="submit" name="submit"/>';
$i++;
echo '</div>';
echo '</div>';
}
echo '</form>';
if (isset($_GET['submit'])) {
$example = $_GET['t'];
foreach ($example as $value) {
$array[$i++] = ($value);
echo "$array[0] <br>"; // printing correct statement but replacing old values with new value everytime.
echo "$array[1] <br>"; // 0 values
echo "$array[2] <br>"; // 0 values
}
}
}
?>
I have seen these posts: PHP array indexing: $array[$index] vs $array["$index"] vs $array["{$index}"] , PHP - define static array of objects but no help. Kindly help what should i do?
You cannot do
$array[$i++]
this will always be $array[1]
instead do
$i++;
$array[$i]= $value;
P.S. $array is a terrible name for a variable...
if (isset($_GET['submit'])) {
$example = $_GET['t'];
$i=0;
$arrayA = array();
foreach ($example as $value) {
$arrayA[$i] = ($value);
$i++;
}
print_r($arrayA);
}
if you do
$array[$i++] ;
it wont work , just try this and it wont replace your old value
$array[$i] = $value;
$i++;
You must increment your variable first, then use the variable as the array key.
Edit: this is what you're looking for:
$i = 0;
foreach ($example as $value) {
$array[$i] = $value;
$i++;
}
i have code which from given path makes something like breadcrumb navigation. I didnt wrote that code, but i think i understand it except two things in url replacement.
Code is like this, and i cant figure out, why replace space with _-_-- and slash with _-_-_. Is there some common point in this?
function listLinksRecursive($path){
echo "<br>recursive : " . $path;
$path = str_replace("X:/","",$path);
$path = str_replace("X:","",$path);
$header = str_replace("_"," ", $path);
echo "<br>first header ". $header;
$header = str_replace("-"," ", $header);
echo "<br>second header ". $header;
echo "<br>";
$linksarray = explode ("/",$header);
$linksarrayreal = explode("/",str_replace(" ","_-_--",$path));
var_dump($linksarray);
echo "<br>";
var_dump($linksarrayreal);
echo "FOLDER: ";
echo ("<a href='http://sjabcz-vyv-bck/cae/index.php?lvl=0&idpath=' rel='nofollow'>04_Knowledge-base</a> / ");
for ($i=0; $i < count($linksarray); $i++){
$linkpath = "";
for ($j = 0; $j <=$i; $j++){
$linkpath = $linkpath . $linksarrayreal[$j];
if ($j < $i){
$linkpath = $linkpath . "_-_-_";
}
}
if ($i < count($linksarray)-1){
echo ("<a href = 'http://sjabcz-vyv-bck/cae/index.php?lvl=0&idpath=$linkpath' rel='nofollow'>$linksarray[$i]</a> / ");
}
if ($i == count($linksarray)-1){
echo ("<b>$linksarray[$i]</b>");
}
}
echo "<p>";
}
These errors keep coming after changing the PHP website to new server.
1st - Solved by "shaddy"
Notice: Undefined variable: es in /home/musthand/public_html/external/site/header.php on line 2
<?php
if(!is_object($es))
{
require_once('includes/EliteScript.php');
$es = new EliteScript();
$sMemberId = $es->getMemberId();
}
// Get the base URL
$sBaseUrl = $es->getConfig('baseUrl');
$sImageUrl = $es->getConfig('imageUrl');
$sMemberId = $es->getMemberId();
$sUsername = $es->getMemberUsername($sMemberId);
$sIP = $_SERVER['REMOTE_ADDR'];
// Vars we want to pass to the system
$aJSVars = array(
'member_url' => $es->getConfig('memberUrl'),
'base_url' => $es->getCOnfig('baseUrl'),
'image_url' => $es->getConfig('imageUrl'),
'date' => date("F d, Y H:i:s", time()),
);
$ba = new BannerAd();
?>
2nd
Fatal error: Class 'FOrum' not found in /home/musthand/public_html/interface/forum.php on line 33
<?php
global $es;
global $ui;
global $member_id;
global $base_url;
global $member_url;
global $image_url;
global $admin_url;
require_once("includes/EliteScript.php");
$es = new EliteScript();
$ui = new UserInterface();
$es->RequireMember();
$member_id = $es->GetMemberId();
$base_url = $es->GetConfig("baseUrl");
$member_url = $es->GetConfig("memberUrl");
$image_url = $es->GetConfig("imageUrl");
$es->DisplayHeader("Forum", "member.php");
$_REQUEST["do"];
display_main();
$es->DisplayFooter();
function display_main()
{
global $es;
global $ui;
global $member_id;
global $base_url;
global $member_url;
global $image_url;
global $admin_url;
$cur_sign = $es->GetCurrencySign();
$f = new FOrum();
echo "<script>\n</script>\n\n<div class=\"bigHeader\">Forum</div>\n";
echo $ui->GenerateMessageBox("msg", 0, 5);
echo $ui->GenerateErrorBox("err", 0, 5);
echo "\n";
echo $ui->DisplayToolTip("Forum", "Below you can participate in the company forum.");
echo "<br>\n\n\n";
$q = "SELECT * FROM forumSections ORDER BY id";
$r = mysql_query($q);
while( $l = mysql_fetch_array($r) )
{
$l_sid = $l["id"];
$l_sec_name = htmlentitiesi($l["name"]);
echo "<div class=\"header\">";
echo $l_sec_name;
echo "</div>\n<table cellspacing=\"1\" cellpadding=\"0\" border=\"0\" width=\"100%\" class=\"dataTbl\">\n<tr class=\"tblHeader\">\n<td>Forum</td>\n<td width=\"50\" align=\"center\">Topics</td>\n<td width=\"50\" align=\"center\">Replies</td>\n<td width=\"150\" align=\"right\">Last Post Info</td>\n</tr>\n";
$html = NULL;
$qb = "SELECT * FROM forums WHERE sectionId='" . $l_sid . "' ORDER BY id";
$rb = mysql_query($qb);
while( $lb = mysql_fetch_array($rb) )
{
$l_fid = $lb["id"];
$l_name = htmlentitiesi($lb["name"]);
$l_desc = htmlentitiesi($lb["description"]);
$l_topics = $f->GetForumTopicCount($l_fid);
$l_replies = $f->GetForumReplyCount($l_fid);
$html .= "<tr class=\"tblRowA\">\n\t\t\t<td style=\"padding: 5px 0px 5px 5px;\">\n\t\t\t<b>" . $l_name . "</b>\n\t\t\t<div style=\"padding-top: 5px;\">\n\t\t\t" . $l_desc . "\n\t\t\t</div>\n\t\t\t\n\t\t\t</td>\n\t\t\t<td align=\"center\">" . $l_topics . "</td>\n\t\t\t<td align=\"center\">" . $l_replies . "</td>\n\t\t\t<td align=\"right\">" . $l_lastpost . "</td>\n\t\t\t</tr>";
}
echo $html;
echo "</table>\n\n";
}
echo "\n\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n\n\n\n\n\n<div class=\"header\">News & Updates</div>\n<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%\">\n";
$html = NULL;
$q = "SELECT * FROM news ORDER BY added DESC,id DESC LIMIT 5";
$r = mysql_query($q);
while( $l = mysql_fetch_array($r) )
{
$l_id = $l["id"];
$l_title = htmlentitiesi($l["title"]);
$l_date = date("M jS", strtotime($l["added"]));
$html .= "<tr class=\"sepLine\"><td width=\"20\"><img src=\"" . $image_url . "/note.png\" width=\"16\" height=\"16\"></td><td>" . $l_title . " <i style=\"color:gray;\">(" . $l_date . ")</i></td></tr>\n";
}
if( !$html )
{
$html = "<tr class=\"sepLine\"><td style=\"color: gray;\">Currently no news and updates...</td></tr>";
}
echo $html;
echo "</table>\n<br>\n\n<div class=\"header\">Account Summary</div>\n\n<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%\">\n<tr class=\"sepLine\">\n<td width=\"20\"><img src=\"";
echo $image_url;
echo "/user.png\" width=\"16\" height=\"16\"></td>\n<td width=\"175\"><b>Member Info:</b></td>\n<td>";
echo $username;
echo " (#";
echo $member_id;
echo ") <i>(<a href=\"mailto:";
echo $email;
echo "\">";
echo $email;
echo "</a>)</i></td>\n<td align=\"right\"><a href=\"";
echo $member_url;
echo "/preferences.php\">[Preferences]</a></td>\n</tr>\n</table>\n\n<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%\">\n<tr><td class=\"toolTip\">\nYou must ";
echo $req_text;
echo " before participating.</td></tr>\n</table>\n\n\n\n\n<div class=\"header\">Current Active ";
echo $token_label;
echo "s</div>\n\n<table cellspacing=\"1\" cellpadding=\"0\" border=\"0\" width=\"100%\" class=\"dataTbl\">\n<tr class=\"tblHeader\">\n<td width=\"50\">ID</td>\n<td>Type</td>\n<td width=\"40\">Units</td>\n<td width=\"80\">Amount</td>\n<td width=\"150\">Earned So Far</td>\n<td width=\"80\">Created</td>\n</tr>\n\n";
$tok_types = $es->GetConfig("tokenTypes");
$html = NULL;
$tblClass = "tblRowA";
$q = "SELECT * FROM tokens WHERE memberId='" . $member_id . "' AND status = 'ACTIVE' ORDER BY created DESC,id DESC";
$r = mysql_query($q);
while( $l = mysql_fetch_array($r) )
{
$l_id = $l["id"];
$l_type = $l["type"];
$tok_arr = $tok_types[$l_type];
$l_name = htmlentitiesi($tok_arr["name"]);
$l_amt = $l["amount"];
$l_esf = $l["earnedSoFar"];
$l_exp_type = $l["expireType"];
$l_exp_val = $l["expiresOnValue"];
$l_created = $l["createdDate"];
$l_lastroi = $l["lastRoiDate"];
$l_incycle = $l["inCycle"];
$l_status = $l["status"];
if( $l_status == "ACTIVE" )
{
$lb_status = "<span style=\"color: darkgreen;\">Active</span>";
}
else
{
if( $l_status == "EXPIRED" )
{
$lb_status = "<span style=\"color: red;\">Expired</span> as of " . date("M jS, y", strtotime($l["expiresDate"]));
}
}
if( $l_created == $l_lastroi && $l_incycle <= 1 )
{
$l_lastearn_text = "Never";
}
else
{
$l_lastearn_text = date("M jS, y", strtotime($l_lastroi));
}
$l_units = sprintf("%d", $l["units"]);
$l_earned_per = sprintf("%.2f", $l_esf / $l_amt * 100);
$earned_per_style = "color: gray;";
if( 100 < $l_earned_per )
{
$earned_per_style = "color: darkgreen;";
}
$l_created_date = date("M jS, y", $l["created"]);
if( $l_exp_type == "value" )
{
$l_exp_text = sprintf("%.2f", $l_exp_val) . "%";
$l_exp_text .= " <i>(" . $cur_sign . sprintf("%.2f", $l_amt * $l_exp_val / 100) . ")</i>";
}
else
{
if( $l_exp_type == "date" )
{
$l_exp_text = date("M jS, y", $l["expires"]);
}
else
{
if( $l_exp_type == "never" )
{
$l_exp_text = "No Set Expiry";
}
}
}
$lb_amt = number_format($l_amt, 2);
$lb_esf = number_format($l_esf, 2);
$html .= "\n\t\t<tr class=\"" . $tblClass . "\">\n\t\t<td>#" . $l_id . "</td>\n\t\t<td><b>" . $l_name . "</b></td>\n\t\t\n\t\t<td>" . $l_units . "</td>\n\t\t<td>" . $cur_sign . $lb_amt . "</td>\n\t\t<td>" . $cur_sign . $lb_esf . " <i style=\"" . $earned_per_style . "\">(" . $l_earned_per . "%)</i></td>\n\t\t<td>" . $l_created_date . "</td>\n\t\t</tr>\n\t\t<tr class=\"" . $tblClass . "\">\n\t\t<td colspan=\"6\" style=\"padding-left: 20px;\">\n\t\t\n\t\t<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\">\n\t\t<tr><td width=\"170\">\n\t\t<u>Last Earn Date:</u> " . $l_lastearn_text . "\n\t\t</td><td width=\"190\">\n\t\t<u>Expires:</u> " . $l_exp_text . "\n\t\t</td><td>\n\t\t<u>Status:</u> " . $lb_status . "\n\t\t</td></tr>\n\t\t</table>\n\t\t\n\t\t</td>\n\t\t</tr>";
$tblClass = $tblClass == "tblRowA" ? "tblRowB" : "tblRowA";
}
if( !$html )
{
$html .= "<tr class=\"" . $tblClass . "\"><td colspan=\"7\"><span style=\"color: gray;\">Currently no active " . $token_label . "s...</span></td></tr>";
}
echo $html;
echo "</table>\n\n<br><br>\n\n";
}
?>
They used to work fine on old server, I don't know what's up with these errors on new one.
They're defined somewhere in somefile, there are 800+ files and it's hard to search in each and every.
Is there any way that we can make the server look of the actual file where these classes or variables were defined?
Your code was never working well. It is bad written. The reason you did not see errors, in your old server is that you had lower error reporting or the whole error reporting was turned off. When you are developing something you should always develop with turned on error reporting, so you can see your mistakes.
The first problem is here
if(!is_object($es)) {
You check directly if $es is object, but this is wrong, because this statement is at the top of the file, and $es will be aways undefined unless you import it from the global scope, like this:
global $es;
if(!is_object($es)) {
Your second error is because you have referenced wrongly the Forum class:
$f = new FOrum();
I suppose it should be:
$f = new Forum();