Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> Modules
Author Message
Donovan
Client



Joined: Oct 07, 2003
Posts: 735
Location: Ohio

PostPosted: Sun Dec 03, 2006 4:32 pm Reply with quote

Working on a custom module.

The error is below.

Quote:
Fatal error: Call to a member function on a non-object in /home/xxxxxxxx/public_html/modules/Campaign/common.php on line 24


An the entire common.php file is below.

Code:
<?php

/************************************************************************
* ETO Campaign Mod
* By: Donovan [3rd ID]
* http://www.eto-league-com
* Copyright © 2006 by ETO
* License: GNU/GPL
************************************************************************/

/*********************************************************/
/* Common functions                                      */
/*********************************************************/
if ( !defined('MODULE_FILE') )
{
   die("You can't access this file directly...");
}
require_once("mainfile.php");
$module_name = basename(dirname(__FILE__));
global $db, $prefix, $module_name, $admin_file;

function verifymove($team_id){

$verify = 0;
$sql = $db->sql_query("SELECT * FROM " . $prefix . "_eto_tracking WHERE dteam_id ='$team_id' AND move_dt >= DATE_SUB(current_timestamp, interval 2 day)");


//$sql = "SELECT * FROM " . $prefix . "_eto_tracking WHERE dteam_id ='$team_id' AND move_dt >= DATE_SUB(current_timestamp, interval 2 day)";

//$result = $db->sql_query($sql);
   if ($db->sql_numrows($sql) > 0) {
      $verify = 1;
   OpenTable();
   echo 'Your unit is currently under attack. Monitor your challeges in Titancore for pending challenges';
   CloseTable();
}else{
   return $verify;

}
}

?>


It errors on this line.

Code:
$sql = $db->sql_query("SELECT * FROM " . $prefix . "_eto_tracking WHERE dteam_id ='$team_id' AND move_dt >= DATE_SUB(current_timestamp, interval 2 day)");


I did have it written this way but had the same result.

Code:
$result = $db->sql_query($sql);


Why would it error on $result = $db->sql_query ?
 
View user's profile Send private message Visit poster's website ICQ Number
fkelly
Former Moderator in Good Standing



Joined: Aug 30, 2005
Posts: 3312
Location: near Albany NY

PostPosted: Sun Dec 03, 2006 7:20 pm Reply with quote

Well, to start with your global statement is outside of the function so it won't do any good there, the variables won't be accessible inside the function.

So probably as a result the variable $db isn't available and therefore your program can't deal with db->sql_query which is defined in mysql.php in the /db directory. Mainfile calls db.php which in turn includes mysql.php which defines db->sql_query.

So start with moving that.

You could also echo out any mysql error messages something along the lines of:

Code:
echo 'sql failed . <br />';

            echo 'query was ' . $query . '<br />';
            echo mysql_errno() . '<br />';
            echo mysql_error() . '<br />';
            die();


Where you could substitute in $sql for $query. But in the statement:

Code:
$sql = $db->sql_query("SELECT * FROM " . $prefix . "_eto_tracking WHERE dteam_id ='$team_id' AND move_dt >= DATE_SUB(current_timestamp, interval 2 day)");



What is going into $sql is really just a result identifier. That's why programmers usually use $result where you now have $sql. You can do a test for "if (!result) { ..." to do the echoes I listed.

After you get something into $result then you have to do a fetchrow or something similar to get actual field values out. But the first step is to debug your SQL statement and make sure it executes successfully. You can also use numrows statements to see how many rows are returned.
 
View user's profile Send private message Visit poster's website
Donovan







PostPosted: Sun Dec 03, 2006 8:04 pm Reply with quote

That did it. I put the globals statements inside the function and it works.

Does my logic look correct to check for the past 48 hours?

Would this work?

Code:
move_dt >= DATE_SUB(current_timestamp, interval 48 hour)";


I'm a bit confused with using >= and dates.

>= is saying older than 48 hours right?
 
fkelly







PostPosted: Sun Dec 03, 2006 8:47 pm Reply with quote

Glad relocating the global helped. Someone else will need to help you with the logic, that's not one of my strong suites. I think what I'd do is play with some test data under different conditions and see what happens if I couldn't figure out how the functions work from the MYSQL manual or by Googling. But maybe someone else here knows more about how those functions work.
 
Donovan







PostPosted: Sun Dec 03, 2006 9:24 pm Reply with quote

Thanks for your help.

My other version is the following:

Code:
$sql = "SELECT * FROM " . $prefix . "_eto_tracking WHERE dteam_id ='$team_id' AND move_dt < DATE_SUB(NOW(), INTERVAL 48 HOURS)";


I think this is right since my move_dt I am looking for will be anything within the last 48 hours. If I get a result then:

Code:
if ($db->sql_numrows($result) > 0) {

      $verify = 1;
   OpenTable();
   echo "<center><h3><b>" . _MOVEDISABLED. "</b></h3></center><br><br>"
   ."<center><h3><b> Your unit is currently under attack. Monitor your team in Titancore for pending challenges! </b></h3></center><br><br>";
   CloseTable();
   exit();
}


move_dt data type is timestamp so maybe this wont work.
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> Modules

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©