SQL Query Into Function, Page Stops Working
#1
I had originally posted this in the discord server but realized it would probably do better as a support thread just incase someone else comes across a similar issue as I've had no success at finding similar support threads (or I am not typing in the right keywords).



I'm building a plugin that will display a list/directory based upon a set of restrictions via plugin settings. I haven't figured out how to implement the settings into the query just yet so for the time being I am testing this with usergroup 4 and profile field id 4.

The plugin works just fine when I leave out the guts: https://gyazo.com/190821328f68fc20f99ea104b73afd6b
function fc_directory_start()
{
    global $mybb, $templates, $lang, $header, $headerinclude, $footer;

    if($mybb->get_input('action') == 'fcdirectory')
    {    
    // if its disabled go back to index
    if ($mybb->settings['fc_enable'] != 1) {
            redirect("index.php");
    }
    
    // do guests have permission to view this page? if not display error no perm
    if ($mybb->settings['fc_gvisibility'] != 1 && $mybb->user['uid'] == 0) {
        error_no_permission();
    }

        // breadcrumb because where are we?
        add_breadcrumb('Face Claim Directory', "misc.php?action=fcdirectory");



        // Using the misc_help template for the page wrapper
        eval("\$page = \"".$templates->get("fc_directory")."\";");
        output_page($page);
    }
}

However, when I add the query the page says:
Quote:This page isn’t working
websitename.com is currently unable to handle this request.
HTTP ERROR 500
function fc_directory_start()
{
    global $mybb, $templates, $lang, $header, $headerinclude, $footer;

    if($mybb->get_input('action') == 'fcdirectory')
    {	
	// if its disabled go back to index
	if ($mybb->settings['fc_enable'] != 1) {
    		redirect("index.php");
	}
	
	// do guests have permission to view this page? if not display error no perm
	if ($mybb->settings['fc_gvisibility'] != 1 && $mybb->user['uid'] == 0) {
		error_no_permission();
	}

        // breadcrumb because where are we?
        add_breadcrumb('Face Claim Directory', "misc.php?action=fcdirectory");

	// now do the query thing
	$query = $db->query("
		SELECT *
		FROM ".TABLE_PREFIX."users 
		LEFT JOIN ".TABLE_PREFIX."userfields 
		ON ".TABLE_PREFIX."users.uid = ".TABLE_PREFIX."userfields.ufid 
		WHERE ".TABLE_PREFIX."users.usergroup IN (4)
		ORDER BY username ASC
	");
	while($users=$db->fetch_array($query)) {
		$users['avatar'] = $users['avatar'];
		$users['profilelink'] = $users['uid'];
		$users['username'] = format_name($users['username'], $users['usergroup'], $users['displaygroup']);
		$users['faceclaim'] = $users['fid4'];
		
		// does fc exist or no? if not they don't need to be displayed
		if(!$users['faceclaim']) {
			// do nothing
		}
		else {
			eval("\$fc_directory .= \"".$templates->get("fc_entry")."\";");
		}
	}
	// if directory is empty display the empty template
	if(!$fc_directory) {
		eval("\$fc_directory .= \"".$templates->get("fc_entry_empty")."\";");
	}

        eval("\$fcdirectory = \"".$templates->get("fc_directory")."\";");
        output_page($fcdirectory);
    }
}



What am I doing wrong here? This same query works fine as a page of its own when I had it all inside faceclaims.php file like you would create any other custom page. I'm attempting to turn this into a plugin so I can not only change these values from the ACP without file editing but so I can share it with other forum RPG users to make their lives easier.
Reply
#2
(2021-10-12, 11:22 PM)Taylor M Wrote: What am I doing wrong here?

For one thing, it seems that you haven't declared $db as a global variable. Try doing that and see whether it fixes things.
Reply
#3
(2021-10-13, 09:48 AM)Laird Wrote:
(2021-10-12, 11:22 PM)Taylor M Wrote: What am I doing wrong here?

For one thing, it seems that you haven't declared $db as a global variable. Try doing that and see whether it fixes things.

So I ended up actually trying this yesterday to see if perhaps that was the issue but adding the $db variable even without the query in the function the page did the same error.

I ended up splitting this into its own custom php file as the docs suggested "if your custom page has a lot of functionality". I figured I just had too much going on for the function in misc.php action.

It is working just fine now as a separate file. However, I would love to figure out a way to do it with misc action just for the simple fact I would like to learn as much as possible!
Reply
#4
Have a look to your server's log, you'll have a more detailled info about the error.
[MyBB 1.8 mods] - Offer me a coffee
Do not ask me help through PM or Discord
Reply
#5
(2021-10-13, 04:17 PM)Crazycat Wrote: Have a look to your server's log, you'll have a more detailled info about the error.

I get this answer a lot and each time I go to look, I never have an error log?

   
Reply
#6
That appears to be your web server error log. MyBB is capable of logging errors too, including PHP and database errors, and you should enable that logging too:

https://docs.mybb.com/1.8/faq/errors/#en...error-logs
Reply
#7
(2021-10-13, 06:24 PM)Laird Wrote: That appears to be your web server error log. MyBB is capable of logging errors too, including PHP and database errors, and you should enable that logging too:

https://docs.mybb.com/1.8/faq/errors/#en...error-logs

Thanks! I will check this out. Smile
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)