Problem including code

Page 1 of 1

11 Replies - 1034 Views - Last Post: 19 April 2007 - 08:42 AM Rate Topic: -----

#1 nickfzx  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 37
  • Joined: 14-November 06

Problem including code

Post icon  Posted 18 April 2007 - 06:57 PM

Dear dreamincode guys...you have helped me before, maybe you can again :)

so I am trying to include this file from punbb inside the template of coppermine photo gallery:

define('PUN_ROOT', '../punbb/');
include '../punbb/include/common.php';


you have to define PUN_ROOT to include common.php in case you were wondering.

Now if I include this code in a blank php file it runs fine and I am able to use any of the functions in common.php and more importantly functions.php which is an include in common.php.

So there is no problem with the doing the above code when not inside coppermine.

Also the place in the coppermine theme file i am putting this is the recommended place for including custom php inside coppermine...and other php code I have put in the same place runs fine.

But...what happens when I put the above code in my coppermine template is this:

Fatal error: Call to a member function on a non-object in C:\Program Files\xampp\htdocs\punbb\include\functions.php on line 112

now this is line 112 of functions.php:
$result = $db->query('SELECT u.*, g.*, o.logged FROM '.$db->prefix.'users AS u INNER JOIN '.$db->prefix.'groups AS g ON u.group_id=g.g_id LEFT JOIN '.$db->prefix.'online AS o ON o.ident=\''.$remote_addr.'\' WHERE u.id=1') or error('Unable to fetch guest information', __FILE__, __LINE__, $db->error());


The problem is the $db->query bit. $db has been defined as global so that is not the problem...and if I remove everything in the brackets i get the same error so I have narrowed it down to the $db->query bit being the problem.

So my question is...what are all the possible reasons that could be stopping me from running $db->query() inside of my coppermine template.

I am not expecting anyone to give me program specific help...just the general reasons that could be causing this error.

Thankyou in advance for all help :)

Is This A Good Question/Topic? 0
  • +

Replies To: Problem including code

#2 snoj  Icon User is offline

  • Married Life
  • member icon

Reputation: 64
  • View blog
  • Posts: 3,505
  • Joined: 31-March 03

Re: Problem including code

Posted 18 April 2007 - 07:55 PM

Probably because you're not including the necessary files for whatever object is being used by $db.
Was This Post Helpful? 0
  • +
  • -

#3 nickfzx  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 37
  • Joined: 14-November 06

Re: Problem including code

Posted 18 April 2007 - 08:29 PM

View Posthotsnoj, on 18 Apr, 2007 - 07:55 PM, said:

Probably because you're not including the necessary files for whatever object is being used by $db.


the thing is this code works perfectly with no errors when put in any other php file outside of coppermine's code...I don't think I would have to do any additional includes.

I think it is more likely an issue with coppermine not confilicting with the
->query
bit...but I have no clude really where to go from here
Was This Post Helpful? 0
  • +
  • -

#4 snoj  Icon User is offline

  • Married Life
  • member icon

Reputation: 64
  • View blog
  • Posts: 3,505
  • Joined: 31-March 03

Re: Problem including code

Posted 18 April 2007 - 08:41 PM

Could it be then that coppermine is using the exact same variable name internally?
Was This Post Helpful? 0
  • +
  • -

#5 nickfzx  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 37
  • Joined: 14-November 06

Re: Problem including code

Posted 19 April 2007 - 03:35 AM

View Posthotsnoj, on 18 Apr, 2007 - 08:41 PM, said:

Could it be then that coppermine is using the exact same variable name internally?



I thought of this and tried a different name with no luck...I may explore this thought a little more though.
Was This Post Helpful? 0
  • +
  • -

#6 nickfzx  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 37
  • Joined: 14-November 06

Re: Problem including code

Posted 19 April 2007 - 06:24 AM

View Postnickfzx, on 19 Apr, 2007 - 03:35 AM, said:

View Posthotsnoj, on 18 Apr, 2007 - 08:41 PM, said:

Could it be then that coppermine is using the exact same variable name internally?



I thought of this and tried a different name with no luck...I may explore this thought a little more though.




I am now pretty sure it is not an issue with the same variable name...have tested and the error stays the same...it is the "query" bit that is causing the error...not sure why though.
Was This Post Helpful? 0
  • +
  • -

#7 psykoprogrammer  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 2
  • View blog
  • Posts: 72
  • Joined: 09-October 06

Re: Problem including code

Posted 19 April 2007 - 06:27 AM

include '../punbb/include/common.php';


Check your paths. That include statement is a relative path. If the file you are trying to include this in exists in a subdirectory two levels deep, the include will fail. To see if the include is failing change it to "require". Perhaps doing that will give some insight.
Was This Post Helpful? 0
  • +
  • -

#8 nickfzx  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 37
  • Joined: 14-November 06

Re: Problem including code

Posted 19 April 2007 - 07:04 AM

View Postpsykoprogrammer, on 19 Apr, 2007 - 06:27 AM, said:

include '../punbb/include/common.php';


Check your paths. That include statement is a relative path. If the file you are trying to include this in exists in a subdirectory two levels deep, the include will fail. To see if the include is failing change it to "require". Perhaps doing that will give some insight.


I changed it to require and the exact same error still occurs.
Was This Post Helpful? 0
  • +
  • -

#9 nickfzx  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 37
  • Joined: 14-November 06

Re: Problem including code

Posted 19 April 2007 - 07:17 AM

View Postnickfzx, on 19 Apr, 2007 - 07:04 AM, said:

View Postpsykoprogrammer, on 19 Apr, 2007 - 06:27 AM, said:

include '../punbb/include/common.php';


Check your paths. That include statement is a relative path. If the file you are trying to include this in exists in a subdirectory two levels deep, the include will fail. To see if the include is failing change it to "require". Perhaps doing that will give some insight.


I changed it to require and the exact same error still occurs.




I am having no problems running the exact same include inside of wordpress's template file...and my wordpress is installed in the exact same sort of file structure as coppermine is installed in:
it is something like this:
public_html/punbb
public_html/wordpress
public_html/coppermine


ok i have some more insight into what is going wrong.

the coppermine theme file uses a function to include custom php code.

so I am trying to include common.php within a function...and there is a global $db inside common.php

so it may be a problem of scope

this is the code from coppermines theme file:
function pageheader($section, $meta = '')
{
   global $CONFIG, $THEME_DIR;
   global $template_header, $lang_charset, $lang_text_dir;

 if(empty($custom_header)){

define('PUN_ROOT', '../forums/');
include '../forums/include/common.php';

global $pun_user;
	 
}


so i am fairly sure that it is because i am trying to do it within a function.

So is there a way to solve this?

This post has been edited by nickfzx: 19 April 2007 - 07:17 AM

Was This Post Helpful? 0
  • +
  • -

#10 nickfzx  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 37
  • Joined: 14-November 06

Re: Problem including code

Posted 19 April 2007 - 07:23 AM

ok that was quick now i have sorted it out.

just made the variables global:

this is the code that works now:
function pageheader($section, $meta = '')
{
   global $CONFIG, $THEME_DIR;
   global $template_header, $lang_charset, $lang_text_dir;

global $db, $pun_config, $cookie_name, $cookie_seed, $pun_user;

   if(empty($custom_header)){
   
define('PUN_ROOT', '../forums/');
include '../forums/include/common.php';


sorry for all the posts...got there in the end :)
Was This Post Helpful? 0
  • +
  • -

#11 nickfzx  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 37
  • Joined: 14-November 06

Re: Problem including code

Posted 19 April 2007 - 07:35 AM

the code is now working fine -> the common.php file is being included in coppermine and all of it's functions are available.

However it is forcing the custom header function to be placed at the beginning of the page and loads before everything else.

No matter where it is supposed to be on the page!!
Was This Post Helpful? 0
  • +
  • -

#12 nickfzx  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 37
  • Joined: 14-November 06

Re: Problem including code

Posted 19 April 2007 - 08:42 AM

fixed it...I had include this stuff:

 static $custom_header;
	   $custom_header = ob_get_contents();
	 ob_clean();


sorry for so many posts...and thanks for all the help
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1