Topic: Bad error message?

File: /home/synttorg/public_html/forum/header.php
Line: 245

PunBB reported: Unable to fetch the recent topics 

Database reported: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ORDER BY id DESC LIMIT 5' at line 1 (Errno: 1064)

I see error in SQL syntax and .... wonder... sad

how would I go about fixing this?

Re: Bad error message?

Could you paste your copy of header.php?

Re: Bad error message?

<?php


// Make sure no one attempts to run this script "directly"
if (!defined('PUN'))
    exit;

// Send no-cache headers
header('Expires: Thu, 21 Jul 1977 07:30:00 GMT');    // When yours truly first set eyes on this world! :)
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');        // For HTTP/1.0 compability


// Load the template
if (defined('PUN_ADMIN_CONSOLE'))
    $tpl_main = file_get_contents(PUN_ROOT.'include/template/admin.tpl');
else if (defined('PUN_HELP'))
    $tpl_main = file_get_contents(PUN_ROOT.'include/template/help.tpl');

else if (defined('PUN_PORTAL'))
    $tpl_main = file_get_contents(PUN_ROOT.'include/template/PunPortal.tpl');

else
    $tpl_main = file_get_contents(PUN_ROOT.'include/template/main.tpl');


// START SUBST - <pun_include "*">
while (preg_match('#<pun_include "([^/\\\\]*?)\.(php[45]?|inc|html?|txt)">#', $tpl_main, $cur_include))
{
    if (!file_exists(PUN_ROOT.'include/user/'.$cur_include[1].'.'.$cur_include[2]))
        error('Unable to process user include '.htmlspecialchars($cur_include[0]).' from template main.tpl. There is no such file in folder /include/user/');

    ob_start();
    include PUN_ROOT.'include/user/'.$cur_include[1].'.'.$cur_include[2];
    $tpl_temp = ob_get_contents();
    $tpl_main = str_replace($cur_include[0], $tpl_temp, $tpl_main);
    ob_end_clean();
}
// END SUBST - <pun_include "*">


// START SUBST - <pun_content_direction>
$tpl_main = str_replace('<pun_content_direction>', $lang_common['lang_direction'], $tpl_main);
// END SUBST - <pun_content_direction>


// START SUBST - <pun_char_encoding>
$tpl_main = str_replace('<pun_char_encoding>', $lang_common['lang_encoding'], $tpl_main);
// END SUBST - <pun_char_encoding>


// START SUBST - <pun_head>
ob_start();

// Is this a page that we want search index spiders to index?
if (!defined('PUN_ALLOW_INDEX'))
    echo '<meta name="ROBOTS" content="NOINDEX, FOLLOW" />'."\n";

?>
<title><?php echo $page_title ?></title>
<link rel="stylesheet" type="text/css" href="style/<?php echo $pun_user['style'].'.css' ?>" />
<?php

if (defined('PUN_ADMIN_CONSOLE'))
    echo '<link rel="stylesheet" type="text/css" href="style/imports/base_admin.css" />'."\n";

if (isset($required_fields))
{
    // Output JavaScript to validate form (make sure required fields are filled out)

?>
<script type="text/javascript">
<!--
function process_form(the_form)
{
    var element_names = new Object()
<?php

    // Output a JavaScript array with localised field names
    while (list($elem_orig, $elem_trans) = @each($required_fields))
        echo "\t".'element_names["'.$elem_orig.'"] = "'.addslashes(str_replace(' ', ' ', $elem_trans)).'"'."\n";

?>

    if (document.all || document.getElementById)
    {
        for (i = 0; i < the_form.length; ++i)
        {
            var elem = the_form.elements[i]
            if (elem.name && elem.name.substring(0, 4) == "req_")
            {
                if (elem.type && (elem.type=="text" || elem.type=="textarea" || elem.type=="password" || elem.type=="file") && elem.value=='')
                {
                    alert("\"" + element_names[elem.name] + "\" <?php echo $lang_common['required field'] ?>")
                    elem.focus()
                    return false
                }
            }
        }
    }

    return true
}
// -->
</script>
<?php

}

$user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? strtolower($_SERVER['HTTP_USER_AGENT']) : '';
if (strpos($user_agent, 'msie') !== false && strpos($user_agent, 'windows') !== false && strpos($user_agent, 'opera') === false)
    echo '<script type="text/javascript" src="style/imports/minmax.js"></script>';

$tpl_temp = trim(ob_get_contents());
$tpl_main = str_replace('<pun_head>', $tpl_temp, $tpl_main);
ob_end_clean();
// END SUBST - <pun_head>


// START SUBST - <body>
if (isset($focus_element))
{
    $tpl_main = str_replace('<body onload="', '<body onload="document.getElementById(\''.$focus_element[0].'\').'.$focus_element[1].'.focus();', $tpl_main);
    $tpl_main = str_replace('<body>', '<body onload="document.getElementById(\''.$focus_element[0].'\').'.$focus_element[1].'.focus()">', $tpl_main);
}
// END SUBST - <body>


// START SUBST - <pun_page>
$tpl_main = str_replace('<pun_page>', htmlspecialchars(basename($_SERVER['PHP_SELF'], '.php')), $tpl_main);
// END SUBST - <pun_title>


// START SUBST - <pun_title>
$tpl_main = str_replace('<pun_title>', '<h1><span>'.pun_htmlspecialchars($pun_config['o_board_title']).'</span></h1>', $tpl_main);
// END SUBST - <pun_title>


// START SUBST - <pun_desc>
$tpl_main = str_replace('<pun_desc>', '<p><span>'.$pun_config['o_board_desc'].'</span></p>', $tpl_main);
// END SUBST - <pun_desc>


// START SUBST - <pun_navlinks>
$tpl_main = str_replace('<pun_navlinks>','<div id="brdmenu" class="inbox">'."\n\t\t\t". generate_navlinks()."\n\t\t".'</div>', $tpl_main);
// END SUBST - <pun_navlinks>

//PunPortal Language File//
require PUN_ROOT.'lang/'.$pun_user['language'].'/portal.php';
//PunPortal Language File//

// START SUBST - <pun_portal_title>
$tpl_main = str_replace('<pun_portal_title>', '<h1><span>'.pun_htmlspecialchars($pun_config['o_portal_title']).'</span></h1>', $tpl_main);
// END SUBST - <pun_portal_title>

// START SUBST - <pun_portal_desc>
$tpl_main = str_replace('<pun_portal_desc>', '<p><span>'.$pun_config['o_portal_desc'].'</span></p>', $tpl_main);
// END SUBST - <pun_portal_desc>

// START SUBST - <pun_portal_navigation>

if ($pun_config['o_portal_navigation'] == '1')
{
    $tpl_main = str_replace('<pun_portal_navigation>','<div id="portalnavigation" class="block"><h2><span>'.$lang_portal['Navigation'].'</span></h2><div class="box"><div class="inbox">'."\n\t\t\t".generate_pun_portal_sidelinks()."\n\t\t".'</div></div></div>', $tpl_main);
}
else 
    $tpl_main = str_replace('<pun_portal_navigation>','', $tpl_main);
// END SUBST - <pun_portal_navigation>

// START SUBST - <pun_portal_login>

if ($pun_user['g_id'] == PUN_GUEST && $pun_config['o_portal_login'] == '1')
{
    ob_start();
    
require_once PUN_ROOT.'lang/'.$pun_user['language'].'/login.php';
    
$redirect_url = (isset($_SERVER['HTTP_REFERER']) && preg_match('#^'.preg_quote($pun_config['o_base_url']).'/(.*?)\.php#i', $_SERVER['HTTP_REFERER'])) ? htmlspecialchars($_SERVER['HTTP_REFERER']) : 'forums.php';

$required_fields = array('req_username' => $lang_common['Username'], 'req_password' => $lang_common['Password']);
$focus_element = array('login', 'req_username');
?>
<div class="block">
    <h2><span><?php echo $lang_portal['Login'] ?></span></h2>
    <div class="box">
        <form id="portallogin" method="post" action="login.php?action=in" onsubmit="return process_form(this)">
            <div class="inform">
                <input type="hidden" name="form_sent" value="1" />
                            <input type="hidden" name="redirect_url" value="<?php echo $redirect_url ?>" />
                            <label><strong><?php echo $lang_portal['Username'] ?></strong><br /><input type="text" name="req_username" size="18" maxlength="18" tabindex="1" /><br /></label>
                            <label><strong><?php echo $lang_portal['Password'] ?></strong><br /><input type="password" name="req_password" size="17" maxlength="17" tabindex="2" /><br /></label>
                            
                            <p><a href="register.php" tabindex="4"><?php echo $lang_login['Not registered'] ?><br /></a>
                            <a href="login.php?action=forget" tabindex="5"><?php echo $lang_login['Forgotten pass'] ?></a><br /></p>
                        <p><input type="submit" name="login" value="<?php echo $lang_portal['Login'] ?>" tabindex="3" /></p>
            </div>
        </form>
    </div>
</div>
<?php

    $tpl_temp = trim(ob_get_contents());
    $tpl_main = str_replace('<pun_portal_login>', $tpl_temp, $tpl_main);
    ob_end_clean();
}
else
    $tpl_main = str_replace('<pun_portal_login>', '', $tpl_main);
// END SUBST - <pun_portal_login>

// START SUBST - <pun_portal_recent_topics>
if ($pun_config['o_portal_recent_topics'] == '1')
{
ob_start();

$topicslimit = $pun_config['o_portal_topics_limit'];
?>
<div class="block" id="portalrecenttopics">
<h2><span><?php echo $lang_portal['Recent Topics'] ?></span></h2>
    <div class="box">
        <div class="inbox">
        <?
        $result = $db->query('SELECT id, subject, forum_id FROM '.$db->prefix.'topics WHERE forum_id <> '.$pun_config['o_portal_news_id'].' ORDER BY id DESC LIMIT ' .$topicslimit) or error('Unable to fetch the recent topics', __FILE__, __LINE__, $db->error());

        while($cur_topics = $db->fetch_assoc($result))
        {
            $recent_topics = '<ul><li><a href="'.$pun_config['o_base_url'].'/viewtopic.php?id='.$cur_topics['id'].'">'.$cur_topics['subject'].'</a></li></ul>';
        
            echo $recent_topics;
        }
    ?>
        </div>
    </div>
</div>
<?
    $tpl_temp = trim(ob_get_contents());
    $tpl_main = str_replace('<pun_portal_recent_topics>', $tpl_temp, $tpl_main);
    ob_end_clean();
}
else
    $tpl_main = str_replace('<pun_portal_recent_topics>', '', $tpl_main);
// END SUBST - <pun_portal_recent_topics>

// START SUBST - <pun_portal_recent_posts>
if ($pun_config['o_portal_recent_posts'] == '1')
{
    ob_start();

    $postslimit = $pun_config['o_portal_posts_limit'];
    
    
?>
<div class="block" id="portalrecentposts">
<h2><span><?php echo $lang_portal['Recent Posts'] ?></span></h2>
    <div class="box">
        <div class="inbox">
        
    <?
        $result = $db->query('SELECT p.id, p.posted, t.last_post, t.subject, t.forum_id FROM '.$db->prefix.'posts AS p INNER JOIN '.$db->prefix.'topics AS t WHERE p.posted=t.last_post AND t.forum_id <> '.$pun_config['o_portal_news_id'].' ORDER BY p.posted DESC LIMIT ' .$postslimit) or error('Unable to fetch the recent posts', __FILE__, __LINE__, $db->error());

        while($cur_posts = $db->fetch_assoc($result))
        {
            $recent_posts = '<ul><li><a href="'.$pun_config['o_base_url'].'/viewtopic.php?pid='.$cur_posts['id'].'#p'.$cur_posts['id'].'">'.$cur_posts['subject'].'</a></li></ul>';
        
            echo $recent_posts;
        }
    ?>
        </div>
    </div>
</div>
<?
    $tpl_temp = trim(ob_get_contents());
    $tpl_main = str_replace('<pun_portal_recent_posts>', $tpl_temp, $tpl_main);
    ob_end_clean();
}
else
    $tpl_main = str_replace('<pun_portal_recent_posts>', '', $tpl_main);
// END SUBST - <pun_portal_recent_posts>

// START SUBST - <pun_portal_top_posters>
if ($pun_config['o_portal_top_posters'] == '1')
{
    ob_start();

    $posterslimit = $pun_config['o_portal_posters_limit'];
if ($posterslimit > '1')
{    
?>
<div class="block" id="portaltopposters">
<h2><span>Top <? echo $posterslimit ?> Posters</span></h2>
<div class="box">
        <div class="inbox">
<?
}
else
{
?>
<div class="block" id="portaltopposters">
<h2><span><?php echo $lang_portal['Top Poster'] ?></span></h2>
<div class="box">
        <div class="inbox">
    <?
}
    $result = $db->query('SELECT id, username, num_posts FROM '.$db->prefix.'users ORDER BY num_posts DESC LIMIT ' .$posterslimit) or error('Unable to fetch the recent topics', __FILE__, __LINE__, $db->error());
        
        while($cur_posters = $db->fetch_assoc($result))
        {
            $top_posters = '<ul><li><a href="'.$pun_config['o_base_url'].'/profile.php?id='.$cur_posters['id'].'">'.$cur_posters['username'].'</a> ( '.$cur_posters['num_posts'].' )</li></ul>';
        
            echo $top_posters;
        }
    ?>
        </div>
    </div>
</div>
<?
    $tpl_temp = trim(ob_get_contents());
    $tpl_main = str_replace('<pun_portal_top_posters>', $tpl_temp, $tpl_main);
    ob_end_clean();
}
else
    $tpl_main = str_replace('<pun_portal_top_posters>', '', $tpl_main);
// END SUBST - <pun_portal_top_posters>



// START SUBST - <pun_portal_forum_stats>
if ($pun_config['o_portal_forum_stats'] == '1')
{
    ob_start();

$result = $db->query('SELECT COUNT(id)-1 FROM '.$db->prefix.'users') or error('Unable to fetch total user count', __FILE__, __LINE__, $db->error());
$stats['total_users'] = $db->result($result);

$result = $db->query('SELECT id, username FROM '.$db->prefix.'users ORDER BY registered DESC LIMIT 1') or error('Unable to fetch newest registered user', __FILE__, __LINE__, $db->error());
$stats['last_user'] = $db->fetch_assoc($result);

$result = $db->query('SELECT SUM(num_topics), SUM(num_posts) FROM '.$db->prefix.'forums') or error('Unable to fetch topic/post count', __FILE__, __LINE__, $db->error());
list($stats['total_topics'], $stats['total_posts']) = $db->fetch_row($result);
}    

$num_guests = 0;
$users = array();
$result = $db->query('SELECT user_id, ident FROM '.$db->prefix.'online WHERE idle=0 ORDER BY ident', true) or error('Unable to fetch online list', __FILE__, __LINE__, $db->error());

while ($pun_user_online = $db->fetch_assoc($result))
    {
        if ($pun_user_online['user_id'] > 1)
            $users[] = "\n\t\t\t\t".'<dd><a href="'.$pun_config['o_base_url'].'/profile.php?id='.$pun_user_online['user_id'].'">'.pun_htmlspecialchars($pun_user_online['ident']).'</a>';
        else
            ++$num_guests;
    }
    $num_users = count($users);
    
if ($pun_config['o_portal_forum_stats'] == '1')
{
?>
<div class="block" id="portalforumstats">
<h2><span><?php echo $lang_portal['Forum Statistics'] ?></span></h2>
    <div class="box">
        <div class="inbox">
        <dl>
        <dt></dt>
            <dd><?php echo $lang_portal['Number of users'] ?>: <strong><?php echo $stats['total_users'] ?></strong></dd>
            <dd><?php echo $lang_portal['Number of topics'] ?>: <strong><?php echo $stats['total_topics'] ?></strong></dd>
            <dd><?php echo $lang_portal['Number of posts'] ?>: <strong><?php echo $stats['total_posts'] ?></strong></dd>
            <dd><?php echo $lang_portal['Newest user'] ?>: <a href="<? $pun_config['o_base_url'] ?>/profile.php?id=<? $stats['last_user']['id'] ?>"><?php echo  pun_htmlspecialchars($stats['last_user']['username']) ?></a></dd></dl><dl><?
            
            echo "\t\t\t\t".'<dd>'.$lang_portal['Users online'].': <strong>'.$num_users.'</strong></dd>'."\n\t\t\t\t".'<dd>'.$lang_portal['Guests online'].': <strong>'.$num_guests.'</strong></dd>'."\n\t\t\t".'</dl>'."\n"; ?>
        </div>
    </div>
</div>
<?
    $tpl_temp = trim(ob_get_contents());
    $tpl_main = str_replace('<pun_portal_forum_stats>', $tpl_temp, $tpl_main);
    ob_end_clean();
}
else
    $tpl_main = str_replace('<pun_portal_forum_stats>', '', $tpl_main);
// END SUBST - <pun_portal_forum_stats>

// START SUBST - <pun_portal_users_online>
if ($pun_config['o_portal_online'] == '1' && $num_users > 0)
{
    ob_start();

?>
<div class="block" id="portalusersonline">
<h2><span><?php echo $lang_portal['Users online'] ?></span></h2>
    <div class="box">
        <div class="inbox">
        <?php echo "\t\t\t".'<dl id="onlinelist" class= "clearb">'."\n\t\t\t\t".'<dt><strong>'.$lang_portal['Online'].': </strong></dt>'."\t\t\t\t".implode(',</dd> ', $users).'</dd>'."\n\t\t\t".'</dl>'."\n"; ?>
        </div>
    </div>
</div>
<?
    $tpl_temp = trim(ob_get_contents());
    $tpl_main = str_replace('<pun_portal_users_online>', $tpl_temp, $tpl_main);
    ob_end_clean();
}
else
    $tpl_main = str_replace('<pun_portal_users_online>', '', $tpl_main);
// END SUBST - <pun_portal_users_online>

// START SUBST - <pun_portal_forum_search>
if ($pun_config['o_portal_forum_search'] == '1')
{
    ob_start();
    
require_once PUN_ROOT.'lang/'.$pun_user['language'].'/search.php';
?>
<div class="block" id="portalforumsearch">
<h2><span><?php echo $lang_portal['Forum Search'] ?></span></h2>
        <div class="box">
            <form id="search" method="get" action="<?php echo $pun_config['o_base_url'] ?>/search.php">
            <div class="inform">
            <input type="hidden" name="action" value="search" />
            <input style="margin-bottom: 3px" type="text" name="keywords" size="25" maxlength="100" />
            <?php echo $lang_search['Show as'] ?><br />
            <select style="margin-bottom: 3px" name="show_as">
            <option value="topics"><?php echo $lang_search['Show as topics'] ?></option>
            <option value="posts"><?php echo $lang_search['Show as posts'] ?></option>
            </select><br />
            <input type="submit" name="search" value="<?php echo $lang_common['Submit'] ?>" accesskey="s" />
            </div>
        </form>
    <a href="<? echo $pun_config['o_base_url'] ?>/search.php">Advanced Search</a>
    </div>
</div>
<?
    $tpl_temp = trim(ob_get_contents());
    $tpl_main = str_replace('<pun_portal_forum_search>', $tpl_temp, $tpl_main);
    ob_end_clean();
}
else
    $tpl_main = str_replace('<pun_portal_forum_search>', '', $tpl_main);
// END SUBST - <pun_portal_forum_search>

// START SUBST - <pun_portal_ads>
if($pun_config['o_portal_advertisement'] == '1')
{
    ob_start();
    
$advertisement = $pun_config['o_portal_ads'];
?>
<div class="block" id="portalads">
<h2><span><?php echo $lang_portal['Ads'] ?></span></h2>
    <div class="box">
        <div class="inbox">
        <div><?php echo $advertisement ?></div>
        </div>
    </div>
</div>
<?
    $tpl_temp = trim(ob_get_contents());
    $tpl_main = str_replace('<pun_portal_ads>', $tpl_temp, $tpl_main);
    ob_end_clean();
}
else
    $tpl_main = str_replace('<pun_portal_ads>', '', $tpl_main);
// END SUBST - <pun_portal_ads>


// START SUBST - <pun_status>
if ($pun_user['is_guest'])
    $tpl_temp = '<div id="brdwelcome" class="inbox">'."\n\t\t\t".'<p>'.$lang_common['Not logged in'].'</p>'."\n\t\t".'</div>';
else
{
    $tpl_temp = '<div id="brdwelcome" class="inbox">'."\n\t\t\t".'<ul class="conl">'."\n\t\t\t\t".'<li>'.$lang_common['Logged in as'].' <strong>'.pun_htmlspecialchars($pun_user['username']).'</strong></li>'."\n\t\t\t\t".'<li>'.$lang_common['Last visit'].': '.format_time($pun_user['last_visit']).'</li>';

    if ($pun_user['g_id'] < PUN_GUEST)
    {
        $result_header = $db->query('SELECT COUNT(id) FROM '.$db->prefix.'reports WHERE zapped IS NULL') or error('Unable to fetch reports info', __FILE__, __LINE__, $db->error());

        if ($db->result($result_header))
            $tpl_temp .= "\n\t\t\t\t".'<li class="reportlink"><strong><a href="admin_reports.php">There are new reports</a></strong></li>';

        if ($pun_config['o_maintenance'] == '1')
            $tpl_temp .= "\n\t\t\t\t".'<li class="maintenancelink"><strong><a href="admin_options.php#maintenance">Maintenance mode is enabled!</a></strong></li>';
    }

    if (in_array(basename($_SERVER['PHP_SELF']), array('index.php', 'search.php')))
        $tpl_temp .= "\n\t\t\t".'</ul>'."\n\t\t\t".'<ul class="conr">'."\n\t\t\t\t".'<li><a href="search.php?action=show_new">'.$lang_common['Show new posts'].'</a></li>'."\n\t\t\t\t".'<li><a href="misc.php?action=markread">'.$lang_common['Mark all as read'].'</a></li>'."\n\t\t\t".'</ul>'."\n\t\t\t".'<div class="clearer"></div>'."\n\t\t".'</div>';
    else
        $tpl_temp .= "\n\t\t\t".'</ul>'."\n\t\t\t".'<div class="clearer"></div>'."\n\t\t".'</div>';
}

$tpl_main = str_replace('<pun_status>', $tpl_temp, $tpl_main);
// END SUBST - <pun_status>


// START SUBST - <pun_announcement>
if ($pun_config['o_announcement'] == '1')
{
    ob_start();

?>
<div id="announce" class="block">
    <h2><span><?php echo $lang_common['Announcement'] ?></span></h2>
    <div class="box">
        <div class="inbox">
            <div><?php echo $pun_config['o_announcement_message'] ?></div>
        </div>
    </div>
</div>
<?php

    $tpl_temp = trim(ob_get_contents());
    $tpl_main = str_replace('<pun_announcement>', $tpl_temp, $tpl_main);
    ob_end_clean();
}
else
    $tpl_main = str_replace('<pun_announcement>', '', $tpl_main);
// END SUBST - <pun_announcement>


// START SUBST - <pun_main>
ob_start();


define('PUN_HEADER', 1);

Re: Bad error message?

$pun_config['o_portal_news_id'] isn't set, try deleting the config cache file.

Re: Bad error message?

i deleted the cache config file but didn't seem to remedy the issue sad

Re: Bad error message?

Did you run install_mod.php for the mod?

Re: Bad error message?

File: /home/synttorg/public_html/forum/install_mod.php
Line: 27

PunBB reported: Unable to insert into config 

Database reported: Duplicate entry 'o_pun_portal' for key 1 (Errno: 1062)

Re: Bad error message?

http://punbb.org/forums/viewtopic.php?id=15800
You're not the first person with this problem, my guess is that there's a config name/value pair missing from config.php

Re: Bad error message?

er.... so what would you suggest me doing? resorting to one of my back ups and try reinstalling the mod? (which I don't think I made any errors but I guess its possible)

or just find a diff mod to use >.>?

Re: Bad error message?

You could manually insert a row with conf_name of o_portal_news_id and conf_value of x, where x is some forum ID

11

Re: Bad error message?

http://www.punres.org/viewtopic.php?id=2622&p=6

12 (edited by GeoffG 2007-10-11 03:46)

Re: Bad error message?

EDIT**

nvm I have access to my data base

but where would I be adding this again to fix my problem??

could someone walk me through it abit? I've never messed with MySQL before.