Fatal error: Call to a member function Show_LastRec_Pack() on a non-object - function

It has been already 5 days and still can't figure out where's the problem! so here i post the error and the whole code. Hopefully someone can help! I'll appreciate it very much.
Fatal error: Call to a member function Show_LastRec_Pack() on a non-object in packgames.php on line 69
here's "packgames.php":
<?
/**
* Block Last Rec Pack
**/
define ('PACK_GAMES_TO_SHOW', 3);
require_once ('recmod/constants.php');
$query = "SELECT r.*, pp.topic_id, p.Nick, b.*, p.Rating
FROM " . TABLE_RECGAMES . " r, " . $this->db->obj['sql_tbl_prefix'] . "attachments a, " . $this->db->obj['sql_tbl_prefix'] . "posts pp,
" . TABLE_PLAYERS." p, recs_aoc_flags b
WHERE a.attach_id = r.attach_id
AND a.attach_rel_id = pp.pid
AND r.Id_Player > 0
AND p.Id_Player = r.Id_Player
AND b.flag_id = p.flag_id
ORDER BY r.Id_RecordedGame DESC
LIMIT " . PACK_GAMES_TO_SHOW;
$this->DB->query($query);
$packs = array ();
while ($player = $this->DB->fetch ())
{
$flag = '<img src="' . PATH_FLAGS . $player['flag_image'] . '" alt="'.$player['flag_country'].'" title="' . $player['flag_country'] . '" align="absmiddle" border="0">';
$packs[] = array (
'GAMES' => $player['Players'],
'PLAYER' => $player['Nick'],
'FLAG' => $flag,
'RATING' => $player['Rating'],
'ID_POST' => $player['topic_id']
);
}
$tmp = $this->registry->getClass('output')->getTemplate('recgames')->Show_LastRec_Pack ($packs);
echo $tmp;
?>

Whatever that object call template is returning, it's not an object. Do some var_dumps() on the call chain and figure out where a null or other non-object is being returned. Most likely on getTemplate().

Related

Laravel Error : Function name must be a string

$files = $request->file('attachment');
$attachmentDataPush = NULL;
if ($request->hasfile('attachment')) {
foreach ($files as $file) {
$message->attach($file->getRealPath(), [
'as' => $file->getClientOriginalName(),
'mime' => $file->getMimeType()
]);
$filename = 'AttachmentsBox/' . $message->getId() . '/' . $file->getClientOriginalName();
Storage::put($filename, $file->get());
$attachmentDataPush = $attachmentDataPush . "<" . $file()->getClientOriginalName() . ">";
}
}
I want to add the code I wrote in $ attachmentDataPush side by side in <> but it gives an error. "Function name must be a string" What do you think may be the problem. ?
$attachmentDataPush = $attachmentDataPush . "<" . $file()->getClientOriginalName() . ">";
Line gives an error.I will insert the transaction into the database.
$attachmentDataPush = $attachmentDataPush . "<" . $file->getClientOriginalName() . ">";
I functioned as file (). I accidentally put brackets. The top one is correct.

I can't seem to get the IF condition I'm looking for

I have the function working properly, I just cant seem to get the right IF condition to wrap it all in. What I am trying to achieve is only create the link list IF the WHILE has anything to display.
so if I'm on thread id 3 and it has 2 addon thread ids 4,5 it will create:
<ul>
<li>Link 4</li>
<li>Link 5</li>
</ul>
if I'm on thread 2 and it has no addon thread ids it should return nothing.
This is what I currently have with no conditions.
$addonid = $db->query_read ("
SELECT drc.threadid AS threadid
FROM `" . TABLE_PREFIX . "modsys_settings` AS drc
LEFT JOIN `" . TABLE_PREFIX . "thread` AS thread
ON(drc.mod_addons=" . $threadinfo['threadid'] . ")
WHERE thread.threadid IN (" . $threadinfo['threadid'] . ")
");
$post['addons'] = '<ul>';
while ($addons = $db->fetch_array ($addonid)) {
$ci_counter = $db->query_read ("
SELECT drc.mod_addons AS addon, drc.threadid, thread.threadid AS threadid, thread.title AS threadtitle
FROM `" . TABLE_PREFIX . "modsys_settings` AS drc
LEFT JOIN `" . TABLE_PREFIX . "thread` AS thread ON(drc.mod_addons=" . $threadinfo['threadid'] . ")
WHERE thread.threadid IN (" . $addons['threadid'] . ")
");
$counter = $db->fetch_array ($ci_counter);
$post['addons'] .= '<li>'. $counter['threadtitle'] .'</li>';
}
$post['addons'] .= '</ul>';
Can you do something like $addonid->num_rows ?
$show_list = $addonid->num_rows;
if($show_list)
$post['addons'] = '<ul>';
And then after the while
if($show_list)
$post['addons'] = '</ul>';
I dont play much with php, so I will give you general guidelines.
Just use a boolean variable to control when create the init tag and close it.
#i_create_a_tag = false;
while ( something ) {
-- open the tag only once
if (!#i_create_a_tag) {
$post['addons'] = '<ul>';
#i_create_a_tag = true;
}
....
}
-- close the tag if was open
if (#i_create_a_tag) {
$post['addons'] = '</ul>';
}

How to add allow punctuation with sql

I am receiving a syntax error when typing punctuation into my website form such as ' or &. I am using the below code on the page when receiving this error. What am I missing or doing wrong that will fix this issue?
$name=$_REQUEST["title"];
$stdate=$_REQUEST["sdate"];
$endate=$_REQUEST["edate"];
$staddr=$_REQUEST["staddr"];
$addr2=$_REQUEST["staddr2"];
$city=$_REQUEST["city"];
$state=$_REQUEST["state"];
$zip=$_REQUEST["zip"];
$desc=$_REQUEST["desc"];
$file=$_REQUEST['photo'];
$link=$_REQUEST["link"];
$user=$_REQUEST["user"];
/***************** DELETE QUERY ****************************/
$date2 = date('Y-m-d');
$qry = "DELETE FROM table WHERE STR_TO_DATE(`endate`, '%Y-%m-%d') < '".$date2."'";
$del = mysql_query($qry);
$query = "INSERT INTO table (fname,stdate,endate,addr1,addr2,city,state,zip,name,size,type,content,link,description,user) VALUES('" . mysql_real_escape_string($name) . "','$stdate','$endate','" . mysql_real_escape_string($staddr) . "','" . mysql_real_escape_string($addr2) . "','$city','$state','$zip','".str_replace(' ','',$name)."-".$stdate."-".$file.".png','0',' ',' ','" . mysql_real_escape_string($link)."','" . mysql_real_escape_string($desc) . "','$user')";
$q2=mysql_query($query) or die('Error, query failed'. mysql_error());
if($q2) {
echo "ok";
} else {
echo "error ".$query.mysql_error();
}
?>
The issue stems from the query line

How to use IF NULL, do this in MySQL?

I'm trying to build a members-system in which you can view certain values from a database.
It worked, so that was great, but I'm having a problem now because I'm using a NULL value on 'age'.
When viewing a profile page, it looks like this:
$id = $_GET["id"];
$result = mysql_query("SELECT * FROM membersfromsite WHERE `idofmember`=$_GET[id]");
$row = mysql_fetch_array($result);
echo "<b>" . $row['userusername'] . "</b>: </p>"; ?>
<?php
$id = $_GET["id"];
$result = mysql_query("SELECT * FROM membersfromsite WHERE `idofmember`=$_GET[id]");
$noage = mysql_query("SELECT ISNULL([age]) FROM membersfromsite WHERE `idofmember`=$_GET[id]");
while ($row = mysql_fetch_array($result))
{
echo "<p class='middle'>id-number: " . $row['idofmember'] . "<br>";
echo "Username: " . $row['userusername'] . "<br>";
if ($noage)
{
echo "Age not specified";
}
else
{
echo "Age: " .$row['age'] ;
}
}
I have tried all kinds of other things, but the problem which I 'm having is that it either returns 'Age not specified' on every userpage or the age on every userpage, including the pages with a NULL value, which makes it look like:
Age:
The code which you can see above returns the age on every page, including the pages with an age which is set to NULL. What I don't understand is if I change the code to this:
$noage = mysql_query("SELECT * FROM membersfromsite WHERE `idofmember`=$_GET[id] AND age IS NULL");
it simply doesn't work. Since I'm using IS NULL instead of = NULL I don't really see why this shouldn't work, but I guess it has to do with the IF which is inside the 'while' thing, I don't really see in what other way I could fix this though...
I'm having an idea what the problem is, because I think that there is already a MyQS, Query done with Results and $noage is maybe ignored because of this, but I don't know how to solve this.
You don't need to do a whole separate $noage query.
Just do:
if(!$row['age'])
{
echo "Age not specified";
}
else
{
echo "Age: " .$row['age'] ;
}
Instead of if($noage) use if(!$row['age']) and skip the second query.
The other reason your code does not work is that the second query returns an array with something like array('expr1' => 0) which is not false. You only get a false result if nothing is found.
The reason why = NULL does not work? There are books written about it, it is just as it is.
Rather than relying on MySQL to tell us if no age was found or not, we can programatically determine whether the age value is Null right in PHP.
Here is an example:
$id = $_GET['id'];
$result = mysql_query("SELECT * FROM membersfromsite WHERE `idofmember` = '" . mysql_real_escape_string($id) . "'");
while($row = mysql_fetch_array($result)) {
echo '<p class='middle'>id-number: ' . $row['idofmember'] . '<br>';
echo 'Username: ' . $row['userusername'] . '<br>';
if($row['age'] === Null) {
echo "Age not specified";
} else {
echo "Age: " .$row['age'] ;
}
}

MIME E-mail - While loop - Database - Error

Resolved: After installing PHPMailer it now works.
I am trying to use MIME E-mail to send out mail to a large number of members.
Seeing that my web-host has limitations on how long a function can run on their server I had to adjust the old functionality.
This is how I want it to work:
Get every member email-address from database table and create a new table with all of these email-addresses.
In the new table I also create two attributes called "Sent" and "Error".
I am planning to use Cron on this functionality. So that every row of email-addresses eventually will be set with Sent = True(1) or Error = True (1).
There is only one problem. I tried testing this on 4 email-addresses. When one of them returns error all the following email-addresses get the same error.
Example of error messages:
Error: 501 : malformed address: �> may not follow **Probably caused of ÆØÅ**
Error: 501 : domain missing or malformed **Because #service.com is missing**
etc..
Output example:
1: Before function. Error value:
1: After function. Error value: 501 : domain missing or malformed
2012-10-10 20:07:46 : 1: MemberID: 1, Mail:testme
Error: 501 : domain missing or malformed
2: Before function. Error value:
2: After function. Error value: 501 : domain missing or malformed
2012-10-10 20:07:46 : 2: MemberID: 2, Mail:testme#gmail.com
Error: 501 : domain missing or malformed
3: Before function. Error value:
3: After function. Error value: 501 : domain missing or malformed
2012-10-10 20:07:46 : 3: MemberID: 3, Mail:testme#hotmail.com
Error: 501 : domain missing or malformed*
I can't understand why this happens.
######################################
### START NEW MAIL FUNCTION ####
######################################
##############################################
### Deletes table if already exists ####
##############################################
$dropExistingTable = "DROP TABLE IF EXISTS $databaseTableNameContainingMembers";
mysql_query($dropExistingTable) or die(mysql_error());
####################################
### Creating new table ####
####################################
$queryCreateTable = "CREATE TABLE $databaseTableNameContainingMembers(ID mediumint(6) NOT NULL AUTO_INCREMENT, Mail TEXT, MailSent BOOLEAN DEFAULT 0, Error BOOLEAN DEFAULT 0, PRIMARY KEY (ID))";
mysql_query($queryCreateTable) or die(mysql_error());
####################################
### Filling new table ####
####################################
//Now we fill the new table with all our members (MemberID, Mail, Sendt = 0).
while ($medlem = mysql_fetch_array($query_medlem)) {
//insert all member mails to new table
$memberMail = $medlem["Epost"];
$queryInsertMemberToNewTable = "INSERT INTO $databaseTableNameContainingMembers (`Mail`) VALUES ('" . $memberMail . "')";
mysql_query($queryInsertMemberToNewTable) or die(mysql_error());
}
######################################
### Sending function ####
######################################
function sendMail($table, $email_message) {
##########################################
### Selecting the new table ####
##########################################
$querySelectAllMembersThatHasNotAlreadyBeenSentTo = "SELECT * FROM $table WHERE `MailSent` = 0 AND `Error` = 0";
//Selects all members that havent been sendt mail to yet.
$allMembersThatHasNotAlreadyBeenSentTo = mysql_query($querySelectAllMembersThatHasNotAlreadyBeenSentTo) or die("Problem with selecting table. <br>" . mysql_error());
$i = 1;
while ($row = mysql_fetch_array($allMembersThatHasNotAlreadyBeenSentTo)) {
$to_address = $row["Mail"];
$memberId = $row["ID"];
$email_message->SetEncodedEmailHeader("To", $to_address, "");
$error = "";
echo $i . ": Before function. Error value: " . $error . "</br></br>";
$error = $email_message->Send();
echo $i . ": After function. Error value: " . $error . "</br></br>";
echo "</br>";
if (strcmp($error, "") > 0) {
##########################################################
### IF ERROR UPDATE MEMBER VARIABLE "Error" ####
##########################################################
updateErrorToMember($memberId, $table, 1);
echo date("Y-m-d H:i:s") . " : " . $i . ": MemberID: " . $memberId . ", Mail:" . $to_address . "</br>Error: $error </br></br></br>";
} else {
##################################################################
### IF SENDING SUCCEEDS UPDATE MEMBER VARIABLE "Sent" ####
##################################################################
updateSentToMember($memberId, $table);
echo date("Y-m-d H:i:s") . ": " . $i . " : Message sent to $to_address<br></br>";
}
$i++;
} //while
}//function
######################################
### End of sending function ####
######################################
######################################
### Run sending function ####
######################################
sendMail($databaseTableNameContainingMembers, $email_message);
You are not clearing the $email_message object after each send, you are using the same $email_message object, just appending new addresses and sending, if one of those addresses are incorrect you carry on the error to the following recipients.
You could try replacing your following code:
$email_message->SetEncodedEmailHeader("To", $to_address, "");
for this one:
$email_message->ClearAddresses();
$email_message->AddAddress($to_address, $to_address);
$headers = "MIME-Version: 1.0"."\r\n";
$headers .= "Content-type:text/html; charset=utf-8"."\r\n";
$headers .= "Reply-To: ". $from . "\r\n";
$headers .= "From: ".$from."\r\n";
$message = '<html><body>';
$message .= stripslashes($msg);
$message .= '</body></html>';
if(mail($to_address, $subject, $message, $headers)){
updateSentToMember($memberId, $table);
echo date("Y-m-d H:i:s") . ": " . $i . " : Message sent to $to_address<br></br>";
}else{
updateErrorToMember($memberId, $table, 1);
echo date("Y-m-d H:i:s") . " : " . $i . ": MemberID: " . $memberId . ", Mail:" . $to_address . "</br>Error: $error </br></br></br>";
}
Just try like this PHP mail() Function if its worked well then i can sure that the issue is in phpMailer Class.