MyBB Community Forums

Full Version: Custom Page Plugin throwing Errors
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have the custom pages MOD installed.

I keep getting an internal MyBB error. Im not sure what is causing it.

<?php

global $headerinclude, $header, $theme, $footer, $lang;

if(!$mybb->user['uid'])
{
 error_no_permission();
}

$lang->load('modcp');
/* Connect to the user list database and select only members of user group 4 (Admins) */
$userquery = $db->simple_select("users", "username, usergroup, regdate", "usergroup=4" , array("order_by" => 'regdate', "order_dir" => 'DESC'));

if ($db->num_rows($usrequery) > 0)
{
	$usertablerows = "";
	while ($users = $db->fetch_array($userquery))
	{
                            $staffuser = get_user($userquery['uid']);
                            $regdate = my_date($mybb->settings['dateformat'], $users['regdate']);
		
                            $usertablerows .= '<tr>
		<td class="trow1">'. build_profile_link($staffuser['username'], $staffuser['uid']). '</td>
		<td class="trow1">'. my_date($mybb->settings['dateformat'], $users['regdate']) .'</td>
		</tr>';
	}
}
else
{
	$usertablerows = '<tr><td class="trow1" colspan="2" align="center">'. $lang->no_banned .'</td></tr>';
}

$template='<html>
<head>
<title>'.$pages['name'].'</title>
{$headerinclude}
</head>
<body>
{$header}
<table border="0" cellspacing="1" cellpadding="2" class="tborder">
<tr><td class="thead" colspan="4"><strong>The Staff</strong></td></tr>
<tr>
<td class="tcat"><span class="smalltext"><strong>Username</strong></span></td>
<td class="tcat"><span class="smalltext"><strong>Registered</strong></span></td>

</tr>
{$usertablerows}
</table>
{$footer}
</body>
</html>';

$template=str_replace("\'", "'", addslashes($template));

add_breadcrumb($pages['name']);

eval("\$page=\"".$template."\";");

output_page($page);

?>
Since you are using PHP in it the next two lines after the starting php tag need to be:
define("IN_MYBB", 1);
require_once "global.php";
Thanks, however it's still throwing an error.

The following warnings occurred:
Warning [2] mysqli_num_rows() expects parameter 1 to be mysqli_result, null given - Line: 475 - File: inc/db_mysqli.php PHP 5.4.29 (Linux)

Heres the code as it is (don't remember if i made minor changes).

Im getting a php error now.

Fatal error: Cannot use object of type mysqli_result as array in /home2/benc/public_html/inc/plugins/pagemanager.php(799) : eval()'d code on line 25

<?php

define("IN_MYBB", 1);
require_once "global.php"; 

global $headerinclude, $header, $theme, $footer, $lang;

if(!$mybb->user['uid'])
{
 error_no_permission();
}

$lang->load('modcp');

$userquery = $db->simple_select("users", "uid, username, usergroup, regdate", "usergroup=4" , array("order_by" => 'regdate', "order_dir" => 'DESC'));


if ($db->num_rows($userquery) > 0)
{
	$usertablerows = "";
	while ($users = $db->fetch_array($userquery))
	{
                            $staffuser = array(get_user($userquery['uid']));
                            $regdate = my_date($mybb->settings['dateformat'], $users['regdate']);
		
                            $usertablerows .= '<tr>
		<td class="trow1">'. build_profile_link($staffuser['username'], $staffuser['uid']). '</td>
		<td class="trow1">'. my_date($mybb->settings['dateformat'], $users['regdate']) .'</td>
		</tr>';
	}
}
else
{
	$usertablerows = '<tr><td class="trow1" colspan="2" align="center">'. "Returned nothing. Something went wrong." .'</td></tr>';
}

$template='<html>
<head>
<title>'.$pages['name'].'</title>
{$headerinclude}
</head>
<body>
{$header}
<table border="0" cellspacing="1" cellpadding="2" class="tborder">
<tr><td class="thead" colspan="4"><strong>The Staff</strong></td></tr>
<tr>
<td class="tcat"><span class="smalltext"><strong>Username</strong></span></td>
<td class="tcat"><span class="smalltext"><strong>Registered</strong></span></td>

</tr>
{$usertablerows}
</table>
{$footer}
</body>
</html>';

$template=str_replace("\'", "'", addslashes($template));

add_breadcrumb($pages['name']);

eval("\$page=\"".$template."\";");

output_page($page);

?>

I'm not sure what the issue is.
1. $userquery['uid'] should be $users['uid']
2. There is no need to wrap the get_user() function with array(), but also...
3. ...I don't see the need for $staffuser at all. It gets the same user and wastes a query. Why don't you simply use $users['username'] and $users['uid']?