Page 1 of 1

Why doesn't this query work?

Posted: Mon May 24, 2004 5:41 pm
by scavok

Code: Select all

<?php
define('IN_PHPBB', true);
$phpbb_root_path = './';
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);

$userdata = session_pagestart($user_ip, PAGE_INDEX);
init_userprefs($userdata);

define('SHOW_ONLINE', true);
$page_title = $lang&#1111;'Index'];
include($phpbb_root_path . 'includes/page_header.'.$phpEx);

$result = 0;

$query = "SELECT user_operation FROM phpbb_users WHERE user_id = $user_id";
$result = $db->sql_query($query);


if ($result == 1)
&#123;
	$template->set_filenames(array(
		'body' => 'operations.tpl')
	);

	$template->pparse('body');
&#125;

include($phpbb_root_path . 'includes/page_tail.'.$phpEx);

?>
I'm trying to modify phpbb code to let me controls users access to certain pages. Since nobody on phpbb's forums has responded to my thread for 2 hours, I'll try here to see if I'm atleast doing the query right.

What I'm trying to do is make sure this person is authorized to load this page. As it stands in this code, result is never = 1. Even when the field I'm trying to get to is set to 1 in the database.

I'm guessing my problem is with the user id. I'm not that sure how to tell who the person is that is currently logged in. This is most likely the case if my problem is not with the query.

If someone could confirm that my code for the query looks alright I would appreciated it.

Posted: Mon May 24, 2004 6:06 pm
by feyd
looks like the query string could use some single quotes in there.. try switching

Code: Select all

$result = $db->sql_query($query);
to

Code: Select all

$result = $db->sql_query($query) or die($db->sql_error());

Posted: Mon May 24, 2004 6:20 pm
by scavok
feyd wrote:looks like the query string could use some single quotes in there.. try switching

Code: Select all

$result = $db->sql_query($query);
to

Code: Select all

$result = $db->sql_query($query) or die($db->sql_error());
Switching that makes just puts the text "Array" on the page below the header. It does not load the body or the footer. I have no idea where it gets "Array" from.

As for the single quotes, do you mean something like this?

Code: Select all

$query = "SELECT 'user_operation' FROM 'phpbb_users' WHERE 'user_id' = '$user_id'";

Posted: Mon May 24, 2004 6:22 pm
by feyd
oops..

Code: Select all

$result = $db->sql_query($query) or die(print_r($db->sql_error(),true));