Why doesn't this query work?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
scavok
Forum Newbie
Posts: 3
Joined: Sun May 23, 2004 10:00 am

Why doesn't this query work?

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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());
scavok
Forum Newbie
Posts: 3
Joined: Sun May 23, 2004 10:00 am

Post 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'";
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

oops..

Code: Select all

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