vForums Support > Programming & Coding :: Programming Discussion :: > Needing some help.

Needing some help. - Posted By Nick (nickb) on 31st Mar 11 at 7:51pm
Ok, I have an affiliate bar set up, that Dwight coded for me, but when things changed the affiliate bar stopped working. Dwight is unable to help right now, so I'm stuck with it not working. This is the error I get inside the affiliate bar:
Fatal error: Cannot redeclare class Database in /home/idirect/public_html/includes/Database.class.php on line 35

Now when I take out /home/idirect/public_html in the line above, it shows the affiliates, but with a set of whole new errors:

[31-Mar-2011 10:37:55] PHP Warning: include() [<a href='function.include'>function.include</a>]: Failed opening '/includes/Database.class.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/idirect/public_html/includes/global.php on line 30

[31-Mar-2011 10:37:56] PHP Warning: include(/includes/Database.class.php) [<a href='function.include'>function.include</a>]: failed to open stream: No such file or directory in /home/idirect/public_html/includes/global.php on line 30


I'm not quite sure what to do. {Unsure}


http://idirectory.us

If you need the files I can send them in PM.

Thanks

Re: Needing some help. - Posted By ashkir (ashkir) on 31st Mar 11 at 10:34pm
For other softwares like drupal/wordpress. This means the functions file went missing.

Re: Needing some help. - Posted By Marc (cr0w) on 1st Apr 11 at 2:38pm
 
Ok, I have an affiliate bar set up, that Dwight coded for me, but when things changed the affiliate bar stopped working. Dwight is unable to help right now, so I'm stuck with it not working. This is the error I get inside the affiliate bar:
Fatal error: Cannot redeclare class Database in /home/idirect/public_html/includes/Database.class.php on line 35

Now when I take out /home/idirect/public_html in the line above, it shows the affiliates, but with a set of whole new errors:

[31-Mar-2011 10:37:55] PHP Warning: include() [<a href='function.include'>function.include</a>]: Failed opening '/includes/Database.class.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/idirect/public_html/includes/global.php on line 30

[31-Mar-2011 10:37:56] PHP Warning: include(/includes/Database.class.php) [<a href='function.include'>function.include</a>]: failed to open stream: No such file or directory in /home/idirect/public_html/includes/global.php on line 30


I'm not quite sure what to do. {Unsure}


http://idirectory.us

If you need the files I can send them in PM.

Thanks


The line I bolded in the quote above explains what the error is. Line 35 in Database.class.php is trying to declare a class that's already been declared somewhere else before. If Database.class.php is a file that came with a pre-built CMS (like Joomla or Wordpress), then their support is probably the best place to go as it's a problem with their system.

However, if Database.class.php is a file you (or Dwight) created, then you simply need to find where the class is first declared, make sure that deleting the class on line 35 won't break things, and then go ahead and delete the duplicate. {Smile}

Re: Needing some help. - Posted By Nick (nickb) on 1st Apr 11 at 7:22pm
Line 35 is just class Database {

and below it is


var $server = ""; //database server
var $user = ""; //database login name
var $pass = ""; //database login password
var $database = ""; //database name
var $pre = ""; //table prefix

and I nor did Dwight create it. I have no clue what to do. Everything pretty much depends on the Database. I don't know what joomla is, but I don't have either joomla or Wordpress.. {Tongue Out}


Re: Needing some help. - Posted By Marc (cr0w) on 1st Apr 11 at 11:21pm
 
Line 35 is just class Database {

and below it is


var $server = ""; //database server
var $user = ""; //database login name
var $pass = ""; //database login password
var $database = ""; //database name
var $pre = ""; //table prefix

and I nor did Dwight create it. I have no clue what to do. Everything pretty much depends on the Database. I don't know what joomla is, but I don't have either joomla or Wordpress.. {Tongue Out}



As I said, "class Database" is defined somewhere else already, which is why the site is throwing errors (you can't have multiple classes with one name, or one class defined numerous times). Joomla and Wordpess are examples of Content Management Systems (CMS); if you use a Content Management System for your website, then their support can likely help better than we can. {Wink}

Whereabouts did you get the backend for your website?

Re: Needing some help. - Posted By Nick (nickb) on 2nd Apr 11 at 5:30am
I see. And Dwight. {Lips Sealed} Our coding is 80% the same I do believe On his and mine, basically copy/paste for him, but he's not in the mood to look into it, and im not gonna push it. {Tongue Out} I'll have a look in my files later and post back here. As I am not quite sure where to go or what to do. {Lips Sealed}

Re: Needing some help. - Posted By Marc (cr0w) on 2nd Apr 11 at 2:52pm
 
I see. And Dwight. {Lips Sealed} Our coding is 80% the same I do believe On his and mine, basically copy/paste for him, but he's not in the mood to look into it, and im not gonna push it. {Tongue Out} I'll have a look in my files later and post back here. As I am not quite sure where to go or what to do. {Lips Sealed}


I feel like the most likely thing that happened is that you include()'d or require()'d the file twice on the same page; the best thing to do is to find all the instances of the database class and replace the include() or the require() (whichever function you're using) with include_once() or require_once(), respectively. These functions check to see if the file has already been included, and only includes it if it hasn't.

Re: Needing some help. - Posted By Nick (nickb) on 2nd Apr 11 at 5:45pm
In my global.php which is included onto most pages it has this, the only ones that dont have this are the categorires. but they do have

<?php
$name = 'Role Play';
include ("./includes/category_core.php");
?>

and this is in the global.php
include("/home/idirect/public_html/includes/Database.class.php");
?>

with out that, it wont work.

But in the 700wideF.php it has this.

<?php
include_once('/home/idirect/public_html/includes/Database.class.php');
include_once('/home/idirect/public_html/includes/global.php');

$db = new Database($DBhost, $DBuser, $DBpass, $DBname, $DBpre);
$db->connect();

$rand_item = mysql_query("SELECT * FROM ads") or die(mysql_error());

echo "<marquee onmouseover=\"this.stop()\" onmouseout=\"this.start()\">";

while($row = mysql_fetch_assoc($rand_item)) {
echo "<a href=\"$row[url]\" target=\"_blank\" /><img src=\"$row[image]\" border=\"0\" ></a> ";
}

echo "</marquee>";

$db->close();
?>

Re: Needing some help. - Posted By Marc (cr0w) on 3rd Apr 11 at 4:06am
Try changing the include() in global.php to include_once() and see if that works. {Smile}

Re: Needing some help. - Posted By Nick (nickb) on 3rd Apr 11 at 2:57pm
{Grin} That worked! Thanks! Smiley

Re: Needing some help. - Posted By Marc (cr0w) on 3rd Apr 11 at 11:56pm
 
{Grin} That worked! Thanks! Smiley


No worries. {Smile}

Re: Needing some help. - Posted By Nick (nickb) on 4th Apr 11 at 4:49am
PHP or any coding can be so difficult. x.x Thanks again. {Smile}