Call to member function sql_query() on a non-object

Post Reply

Topic author
thepips
Active Member
Posts: 22
Joined: 23. December 2008 15:50
phpBB.com User: thepips

Call to member function sql_query() on a non-object

Post by thepips »

Hi,
I'm trying to develop my own block to allow the user to update their location for a weather forecast but I'm getting this error whenever I click submit.

Here's the code for the php action which is where I'm getting the error

Code: Select all

<?php

global $phpbb_root_path, $phpEx, $user, $db, $config, $cache, $template;

/**
 * @author Action Replay
 * @copyright 2009
 */
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : '../../';
$phpEx = substr(strrchr(__FILE__, '.'), 1);

$theuser = $_POST['theuser'];
$thelocation = $_POST['location'];

	if ($theuser != ANONYMOUS)
	{
		//Get the custom profile field for this user
		$sql = 'UPDATE PROFILE_FIELDS_DATA 
				SET pf_location = ' . $thelocation
			 	. ' WHERE user_id = ' . (int) $theuser;
		$result = $db->sql_query($sql);
	}
return($result);
?>
For completeness this is the code for the block

Code: Select all

<?php

	function clean_location($location)
	{		
		//If the location is empty, generate a random location
		if (empty($location))
		{
			/**
			 * We will select a random location and return it
			 * @return string mixed $location
	 		*/
			$location = random_location();
		}
		$location = strip_tags($location, '');
		
		$search = array('%', ' ');
		$replace = array('', ',');
		
		$location = str_replace($search, $replace, $location, $count);	
		
		return $location;
	}
	
	/**
 	* We will select a random location and return it
 	* @return string mixed $location
 	*/
	function random_location()
	{	
		global $user, $auth;
			
			$l_array = array(
				'Basingstoke',
				'Cardiff',
				'Leeds',
				'Birmingham',
				'Manchester',
				'Southampton',
				'London',
				''
			);
			
			$nlocation = $l_array[array_rand($l_array, 1)];
			
			$location = request_var('location', $nlocation);
		
		return $location;
	}

	if (!defined('IN_PHPBB'))
        {
           exit;
        }

    if (!defined('IN_PORTAL'))
        {
           exit;
        }

	$userid_weather = $user->data['user_id'];
	if ($userid_weather > 1)
	{
		$display_menu = true;	
	}
	else
	{
		$display_menu = false;
	}
		
// If the user is logged in

		if ($userid_weather != ANONYMOUS)
		{
			$location = request_var('location', '');
			//Get the custom profile field for this user
//			$user->get_profile_fields($user->data['user_id']);
			
			//If they have a location set, use it
			if (!empty($user->profile_fields['pf_location']))
			{   
			   	$location = $user->profile_fields['pf_location'];
				
				/**
				 * We are cleaning any unwanted data out of the string
				 * @var string mixed
				 */
				$location = clean_location($location);
			}
			else
			{
				/**
				 * We will select a random location and return it
				 * @return string mixed $location
				 */
				$location = random_location();				/**
				 * We are cleaning any unwanted data out of the string
				 * @var string mixed
				 */
				$location = clean_location($location);
			}
			/**
			 * This is where the action starts
			 * @var $location string mixed
			 */			
//			build_weather::get_weather($location);
		}
		// If not logged in, use the default or let them check their weather via URL
		elseif ($userid_weather == ANONYMOUS && !$auth->acl_get('u_weather'))
		{
		   	/**
			 * We will select a random location and return it
	 		 * @return string mixed $location
	 		 */ 
			$location = random_location();
			/**
			 * We are cleaning any unwanted data out of the string
			 * @var string mixed
			 */
			$location = clean_location($location);
		}
	$template->assign_vars(array(
                'WEATHER_LOC'     => (!empty($location)) ? $location : '', 
                'USERID_WEATHER' => $userid_weather,
                'SHOW_SEARCH' => $display_menu,
				'U_UPDATE_LOCATION'		=> append_sid("{$phpbb_root_path}portal/includes/update_location.$phpEx"),
            ));
?>
And finally the code for the html

Code: Select all

{$LR_BLOCK_H_L}<img src="{T_THEME_PATH}/images/portal/portal_weather.png" width="16px" height="16px" alt=""/>&nbsp;Weather{$LR_BLOCK_H_R}                     
<div class="portal-panel">
	<div class="inner">
		<span class="portal-corners-top"><span></span></span>
				<!-- IF SHOW_SEARCH -->
				<form method="post" id="forecast" action="{U_UPDATE_LOCATION}">
					<input type="hidden"
						name="theuser"
						value="{USERID_WEATHER}"
					/>
					<input type="text"
						tabindex="6"
						name="location"
						id="searchfield"
						size="22"
						maxlength="40"
						title="Enter town or postcode"
						class="inputbox search"
						value="{WEATHER_LOC}"
						onclick="if(this.value=='Weather')this.value='{WEATHER_LOC}';"
					/>
					<fieldset class="submit-buttons">
					<input type="reset"
						value="{L_RESET}"
						name="reset"
						class="button2" />
					<input type="submit"
						name="action"
						value="{L_SUBMIT}"
						class="button1" />{S_FORM_TOKEN}
					</fieldset>
				</form></p><!-- ENDIF -->

<!-Weather in {WEATHER_LOC}, UK on your site - HTML code - weatherforecastmap.com --><div align="center"><script src="http://www.weatherforecastmap.com/weather3.php?zona=england_{WEATHER_LOC}"></script><a alt="Weather Today in {WEATHER_LOC}" title="Weather Today in {WEATHER_LOC}" href="http://www.weatherforecastmap.com/england/{WEATHER_LOC}" target='_blank'>Weather Today in {WEATHER_LOC}</a></div><!-end of code-->	<span class="portal-corners-bottom"><span></span></span>

	</div>
</div>
<br style="clear:both" />
           
    {$LR_BLOCK_F_L}{$LR_BLOCK_F_R}
Can anyone shed any light on what I'm doing wrong?

Regards
Doug
Post Reply

Return to “Modifications Support”