Reputation: 639
Can someone help a beginner? It says that Call to a member function set() on a non-object; I have been tinkering with this for 3 days and am unable to figure out what is causing this error.
here is the code
function torrent_download($item_details, $output_type = 'show_torrent')
{
$template->set('session', $session);
$torrent = $show->torrent_download($session->value('user_id'));
{
if ($session->value('is_seller'))
{
$show_tips = $db->count_rows('users', "WHERE user_id='" . $session->value('user_id') . "' AND notif_a=0");
if ($show_tips)
{
$msg_member_tips = '<p class="errormessage">' . MSG_MEMBER_TIPS_A . '<br>' . MSG_MEMBER_TIPS_B . '</p>';
$db->query("UPDATE " . DB_PREFIX . "users SET notif_a=1 WHERE user_id='" . $session->value('user_id') . "'");
}
$template->set('msg_member_tips', $msg_member_tips);
}
if (isset($_REQUEST['form_download_proceed']))
{
$download_result = download_redirect($_REQUEST['winner_id'], $session->value('user_id'));
if ($download_result['redirect'])
{
header('Location: ' . $download_result['url']);
}
$template->set('msg_changes_saved', '<p align="center">' . $download_result['display'] . '</p>');
}
}
}
Upvotes: 0
Views: 177
Reputation: 2006
This generally means your calling something on a variable that's null. What line number is the error returning??
You should add checks after your assignments to ensure the follow are not null:
$download_result, $template, $torrent
From what I can tell, $template is never defined.
Upvotes: 0
Reputation: 324640
I'm assuming you're getting this error inside the torrent_download
function?
If so, that's because $template
is undefined. Perhaps you defined it in the global script, but functions don't inherit that.
You can prevent this issue by adding: global $template
(and any other variable from the outside you need) to the start of your function.
Upvotes: 1